package poussecafe.maven;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import poussecafe.doc.PousseCafeDocletConfiguration;
import poussecafe.doc.PousseCafeDocletExecutor;

import static java.util.Collections.emptyList;

@Mojo(
    name = "generate-doc",
    requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
    requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME
)
public class GenerateDocMojo extends AbstractMojo {

    @Override
    public void execute()
            throws MojoExecutionException,
            MojoFailureException {

        List<String> sourcePath = getSourcePath();
        List<String> classPath = getClassPath();

        PousseCafeDocletConfiguration configuration = new PousseCafeDocletConfiguration.Builder()
                .domainName(domainName)
                .version(version)
                .sourcePath(sourcePath)
                .outputDirectory(outputDirectory.getAbsolutePath())
                .pdfFileName(pdfFileName)
                .basePackage(basePackage)
                .classPath(classPath)
                .customDotExecutable(Optional.ofNullable(customDotExecutable))
                .customFdpExecutable(Optional.ofNullable(customFdpExecutable))
                .build();

        new PousseCafeDocletExecutor(configuration).execute();
    }

    private List<String> getSourcePath() {
        List<String> sourcePath = new ArrayList<>();
        sourcePath.addAll(project.getCompileSourceRoots());
        sourcePath.addAll(sourceDependenciesFiles());
        return sourcePath;
    }

    private List<String> sourceDependenciesFiles() {
        List<String> sourceDependenciesFiles = new ArrayList<>();
        for(Artifact artifact : project.getArtifacts()) {
            if(artifact.hasClassifier() && artifact.getClassifier().equals("sources")) {
                sourceDependenciesFiles.add(artifact.getFile().getAbsolutePath());
            }
        }
        return sourceDependenciesFiles;
    }

    private List<String> getClassPath() {
        List<String> classPath;
        try {
            classPath = project.getCompileClasspathElements();
        } catch (DependencyResolutionRequiredException e) {
            classPath = emptyList();
        }
        return classPath;
    }

    @Parameter(property = "domainName", required = true)
    private String domainName;

    @Parameter(defaultValue = "${project.version}", property = "version", required = true)
    private String version;

    @Parameter(defaultValue = "${basedir}/target/ddd-doc/", property = "outputDirectory", required = true)
    private File outputDirectory;

    @Parameter(property = "basePackage", required = true)
    private String basePackage;

    @Parameter(property = "customDotExecutable")
    private String customDotExecutable;

    @Parameter(property = "customFdpExecutable")
    private String customFdpExecutable;

    @Parameter(defaultValue = "${project.artifactId}-${project.version}.pdf", property = "pdfFileName", required = true)
    private String pdfFileName;

    @Parameter(defaultValue = "${project}", readonly = true, required = true)
    private MavenProject project;
}

@@ -1098,24 +1098,73 @@
 xception %7B%0A%0A
+        if(!Boolean.parseBoolean(skipDoc)) %7B%0A    
         List
@@ -1202,32 +1202,36 @@
 Path();%0A        
+    
 List%3CString%3E cla
@@ -1264,16 +1264,20 @@
         
+   
+ 
 PousseCa
@@ -1374,16 +1374,20 @@
         
+    
 .domainN
@@ -1418,16 +1418,20 @@
         
+  
+  
 .version
@@ -1440,16 +1440,20 @@
 ersion)%0A
+    
         
@@ -1500,16 +1500,20 @@
         
+ 
+   
 .outputD
@@ -1556,16 +1556,20 @@
 Path())%0A
+    
         
@@ -1618,16 +1618,20 @@
         
+    
 .basePac
@@ -1664,16 +1664,20 @@
         
+   
+ 
 .classPa
@@ -1686,24 +1686,28 @@
 (classPath)%0A
+    
             
@@ -1785,24 +1785,28 @@
             
+  
+  
 .customFdpEx
@@ -1872,16 +1872,20 @@
         
+    
 .build()
@@ -1895,16 +1895,20 @@
         
+ 
+   
 new Pous
@@ -1950,24 +1950,34 @@
 .execute();%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -3813,11 +3813,118 @@
 project;
+%0A%0A    @Parameter(property = %22skipDoc%22, required = true, defaultValue = %22false%22)%0A    private String skipDoc;
 %0A%7D%0A

Add flag to skip doc generation.