// Path: ocamljava-maven-plugins/ocamljava-maven-plugin-base/src/main/java/mandelbrot/ocamljava_maven_plugin/OcamlJavaConstants.java
// public static final String COMPILED_IMPL_JAVA_EXTENSION = "cmj";


import static mandelbrot.ocamljava_maven_plugin.OcamlJavaConstants.COMPILED_IMPL_JAVA_EXTENSION;
import java.io.File;
import ocaml.compilers.ocamljavaMain;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.util.FileUtils;
import com.google.common.collect.ImmutableList;

	public ImmutableList<String> gatherOcamlCompiledSources(final File root) {
		final ImmutableList.Builder<String> files = ImmutableList.builder();
		if (root.isFile() && isOcamlCompiledSourceFile(root)) {
			files.add(root.getPath());
			return files.build();
		}
	
		final File[] listFiles; 
		if (!root.isDirectory() || (listFiles = root.listFiles()) == null)
			return files.build();
		
		for (final File file : listFiles) {
			if (file.isDirectory()) {
				getLog().info("scanning directory: " + file);
				
				files.addAll(gatherOcamlCompiledSources(file));
			} else {
				if (isOcamlCompiledSourceFile(file)) {
					getLog().info("adding ocaml source file: " + file);
					files.add(file.getPath());
				}
			}
		}
		return files.build();
	}


	private boolean isOcamlCompiledSourceFile(final File file) {
		final String extension = FileUtils.getExtension(file.getPath());
// Path: ocamljava-maven-plugins/ocamljava-maven-plugin-base/src/main/java/mandelbrot/ocamljava_maven_plugin/OcamlJavaConstants.java
// public static final String COMPILED_IMPL_JAVA_EXTENSION = "cmj";


// Path: ocamljava-maven-plugins/ocamljava-jar-maven-plugin/src/main/java/mandelbrot/ocamljava_maven_plugin/OcamlJavaTestJarMojo.java
import static mandelbrot.ocamljava_maven_plugin.OcamlJavaConstants.COMPILED_IMPL_JAVA_EXTENSION;
import java.io.File;
import ocaml.compilers.ocamljavaMain;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.util.FileUtils;
import com.google.common.collect.ImmutableList;


	public ImmutableList<String> gatherOcamlCompiledSources(final File root) {
		final ImmutableList.Builder<String> files = ImmutableList.builder();
		if (root.isFile() && isOcamlCompiledSourceFile(root)) {
			files.add(root.getPath());
			return files.build();
		}
	
		final File[] listFiles; 
		if (!root.isDirectory() || (listFiles = root.listFiles()) == null)
			return files.build();
		
		for (final File file : listFiles) {
			if (file.isDirectory()) {
				getLog().info("scanning directory: " + file);
				
				files.addAll(gatherOcamlCompiledSources(file));
			} else {
				if (isOcamlCompiledSourceFile(file)) {
					getLog().info("adding ocaml source file: " + file);
					files.add(file.getPath());
				}
			}
		}
		return files.build();
	}


	private boolean isOcamlCompiledSourceFile(final File file) {
		final String extension = FileUtils.getExtension(file.getPath());
		return COMPILED_IMPL_JAVA_EXTENSION.equalsIgnoreCase(extension);