package io.quarkus.gradle;

import java.io.File;
import java.util.Set;

import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.resolver.AppModelResolver;

/**
 * @author <a href="mailto:stalep@gmail.com">Ståle Pedersen</a>
 */
public class QuarkusPluginExtension {

    private final Project project;

    private String transformedClassesDirectory = "transformed-classes";

    private String wiringClassesDirectory = "wiring-classes";

    private String libDir = "lib";

    private String outputDirectory;

    private String finalName;

    private String sourceDir;

    private String workingDir;

    private String outputConfigDirectory;

    public QuarkusPluginExtension(Project project) {
        this.project = project;
    }

    public File transformedClassesDirectory() {
        return new File(project.getBuildDir() + File.separator + transformedClassesDirectory);
    }

    public void setTransformedClassesDirectory(String transformedClassesDirectory) {
        this.transformedClassesDirectory = transformedClassesDirectory;
    }

    public File outputDirectory() {
        if (outputDirectory == null)
            outputDirectory = project.getConvention().getPlugin(JavaPluginConvention.class)
                    .getSourceSets().getByName("main").getOutput().getClassesDirs().getAsPath();

        return new File(outputDirectory);
    }

    public void setOutputDirectory(String outputDirectory) {
        this.outputDirectory = outputDirectory;
    }

    public File outputConfigDirectory() {
        if (outputConfigDirectory == null)
            outputConfigDirectory = project.getConvention().getPlugin(JavaPluginConvention.class)
                    .getSourceSets().getByName("main").getOutput().getResourcesDir().getAbsolutePath();

        return new File(outputConfigDirectory);
    }

    public void setConfigOutputDirectory(String outputDirectory) {
        this.outputConfigDirectory = outputDirectory;
    }

    public File sourceDir() {
        if (sourceDir == null)
            sourceDir = project.getConvention().getPlugin(JavaPluginConvention.class)
                    .getSourceSets().getByName("main").getAllJava().getSourceDirectories().getAsPath();

        return new File(sourceDir);
    }

    public void setSourceDir(String sourceDir) {
        this.sourceDir = sourceDir;
    }

    public File workingDir() {
        if (workingDir == null) {
            workingDir = outputDirectory().getPath();
        }

        return new File(workingDir);
    }

    public void setWorkingDir(String workingDir) {
        this.workingDir = workingDir;
    }

    public File wiringClassesDirectory() {
        return new File(project.getBuildDir() + File.separator + wiringClassesDirectory);
    }

    public void setWiringClassesDirectory(String wiringClassesDirectory) {
        this.wiringClassesDirectory = wiringClassesDirectory;
    }

    public File libDir() {
        return new File(project.getBuildDir() + File.separator + libDir);
    }

    public void setLibDir(String libDir) {
        this.libDir = libDir;
    }

    public String finalName() {
        if (finalName == null || finalName.length() == 0)
            return project.getName() + "-" + project.getVersion();
        else
            return finalName;
    }

    public void setFinalName(String finalName) {
        this.finalName = finalName;
    }

    public boolean uberJar() {
        return false;
    }

    public Set<File> resourcesDir() {
        return project.getConvention().getPlugin(JavaPluginConvention.class)
                .getSourceSets().getByName("main").getResources().getSrcDirs();
    }

    public Set<File> dependencyFiles() {
        SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
        SourceSet sourceSet = sourceSets.getByName("main");
        Set<File> files = sourceSet.getCompileClasspath().getFiles();
        return files;
    }

    public AppArtifact getAppArtifact() {
        return new AppArtifact(project.getGroup().toString(), project.getName(),
                project.getVersion().toString());
    }

    public AppModelResolver resolveAppModel() {
        return new AppModelGradleResolver(project);
    }
}

@@ -151,95 +151,8 @@
 ion;
-%0Aimport org.gradle.api.tasks.SourceSet;%0Aimport org.gradle.api.tasks.SourceSetContainer;
 %0A%0Aim
@@ -403,180 +403,8 @@
 t;%0A%0A
-    private String transformedClassesDirectory = %22transformed-classes%22;%0A%0A    private String wiringClassesDirectory = %22wiring-classes%22;%0A%0A    private String libDir = %22lib%22;%0A%0A
     
@@ -669,322 +669,8 @@
  %7D%0A%0A
-    public File transformedClassesDirectory() %7B%0A        return new File(project.getBuildDir() + File.separator + transformedClassesDirectory);%0A    %7D%0A%0A    public void setTransformedClassesDirectory(String transformedClassesDirectory) %7B%0A        this.transformedClassesDirectory = transformedClassesDirectory;%0A    %7D%0A%0A
     
@@ -981,124 +981,8 @@
  %7D%0A%0A
-    public void setOutputDirectory(String outputDirectory) %7B%0A        this.outputDirectory = outputDirectory;%0A    %7D%0A%0A
     
@@ -1053,32 +1053,34 @@
 rectory == null)
+ %7B
 %0A            out
@@ -1258,32 +1258,41 @@
 AbsolutePath();%0A
+        %7D
 %0A        return 
@@ -1335,136 +1335,8 @@
  %7D%0A%0A
-    public void setConfigOutputDirectory(String outputDirectory) %7B%0A        this.outputConfigDirectory = outputDirectory;%0A    %7D%0A%0A
     
@@ -1383,32 +1383,34 @@
 urceDir == null)
+ %7B
 %0A            sou
@@ -1576,32 +1576,41 @@
 ().getAsPath();%0A
+        %7D
 %0A        return 
@@ -1641,100 +1641,8 @@
  %7D%0A%0A
-    public void setSourceDir(String sourceDir) %7B%0A        this.sourceDir = sourceDir;%0A    %7D%0A%0A
     
@@ -1815,576 +1815,8 @@
  %7D%0A%0A
-    public void setWorkingDir(String workingDir) %7B%0A        this.workingDir = workingDir;%0A    %7D%0A%0A    public File wiringClassesDirectory() %7B%0A        return new File(project.getBuildDir() + File.separator + wiringClassesDirectory);%0A    %7D%0A%0A    public void setWiringClassesDirectory(String wiringClassesDirectory) %7B%0A        this.wiringClassesDirectory = wiringClassesDirectory;%0A    %7D%0A%0A    public File libDir() %7B%0A        return new File(project.getBuildDir() + File.separator + libDir);%0A    %7D%0A%0A    public void setLibDir(String libDir) %7B%0A        this.libDir = libDir;%0A    %7D%0A%0A
     
@@ -1900,16 +1900,18 @@
 () == 0)
+ %7B
 %0A       
@@ -1907,38 +1907,48 @@
 ) %7B%0A            
-return
+this.finalName =
  project.getName
@@ -1992,17 +1992,10 @@
     
-else%0A    
+%7D%0A
     
@@ -2027,160 +2027,8 @@
  %7D%0A%0A
-    public void setFinalName(String finalName) %7B%0A        this.finalName = finalName;%0A    %7D%0A%0A    public boolean uberJar() %7B%0A        return false;%0A    %7D%0A%0A
     
@@ -2229,327 +2229,8 @@
  %7D%0A%0A
-    public Set%3CFile%3E dependencyFiles() %7B%0A        SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();%0A        SourceSet sourceSet = sourceSets.getByName(%22main%22);%0A        Set%3CFile%3E files = sourceSet.getCompileClasspath().getFiles();%0A        return files;%0A    %7D%0A%0A
     

Remove unused methods in QuarkusExtension