package io.doov.gen;

import org.apache.commons.lang3.StringUtils;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class GeneratorPlugin implements Plugin<Project> {
    @Override
    public void apply(Project target) {
        NamedDomainObjectContainer<ModelMapGenerator> container = target.container(ModelMapGenerator.class,
                name -> new ModelMapGenerator(name, target));
        target.getExtensions().add("doovCodeGen", container);
        container.all(modelMap -> {
            ModelMapGenTask task = target.getTasks().create(modelMap.getName(), ModelMapGenTask.class);

            target.afterEvaluate(project -> {
                task.setClasspath(project.getConfigurations().getByName("compile"));
                task.getBaseClassProperty().set(modelMap.getBaseClass());
                task.getOutputDirectory().set(modelMap.getOutputDirectory());
                task.getOutputResourceDirectory().set(modelMap.getOutputResourceDirectory());
                task.getSourceClassProperty().set(modelMap.getSourceClass());
                task.getFieldClassProperty().set(modelMap.getFieldClass());
                task.getPackageFilter().set(modelMap.getPackageFilter());
                task.getEnumFieldInfo().set(modelMap.getEnumFieldInfo());
                task.getFieldPathProviderProperty().set(modelMap.getFieldPathProvider());
                task.getTypeAdaptersProperty().set(modelMap.getTypeAdapters());
                task.getDslModelPackage().set(modelMap.getDslModelPackage());
                task.getWrapperPackage().set(modelMap.getWrapperPackage());
                task.getFieldInfoPackage().set(modelMap.getFieldInfoPackage());
                target.getTasks().getByName("clean").dependsOn("clean" + StringUtils.capitalize(task.getName()));
                target.getTasks().getByName("compileGeneratedJava").dependsOn(task);
            });

        });

    }

}

@@ -30,151 +30,56 @@
 org.
-apache.commons.lang3.StringUtils;%0Aimport org.gradle.api.NamedDomainObjectContainer;%0Aimport org.gradle.api.Plugin;%0Aimport org.gradle.api.Project
+gradle.api.*;%0Aimport org.gradle.api.tasks.Delete
 ;%0A%0Ap
@@ -421,16 +421,112 @@
 ainer);%0A
+        Delete deleteDoovCodeGen = target.getTasks().create(%22deleteDoovCodeGen%22, Delete.class);%0A
         
@@ -1733,32 +1733,33 @@
 InfoPackage());%0A
+%0A
                 
@@ -1762,103 +1762,113 @@
     
-target.getTasks().getByName(%22clean%22).dependsOn(%22clean%22 + StringUtils.capitalize(task.getName())
+deleteDoovCodeGen.delete(modelMap.getOutputDirectory());%0A                task.dependsOn(deleteDoovCodeGen
 );%0A 

Delete all generated task output dirs