package de.is24.deadcode4j.plugin.packaginghandler;

import de.is24.deadcode4j.Repository;
import org.apache.commons.io.filefilter.OrFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
import static org.apache.commons.io.IOCase.INSENSITIVE;
import static org.apache.commons.io.filefilter.DirectoryFileFilter.DIRECTORY;

/**
 * A <code>PackagingHandler</code> determines which code repositories exist for a specific packaging (like "jar", "war", etc.).
 *
 * @since 1.2.0
 */
public abstract class PackagingHandler {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * Returns the "output" repository - i.e. the directory where compiled classes can be found - for the given project.
     *
     * @since 1.2
     */
    @Nullable
    public abstract Repository getOutputRepositoryFor(@Nonnull MavenProject project) throws MojoExecutionException;

    /**
     * Returns additional repositories (configuration, JSPs, raw java files) to analyze for the given project.
     *
     * @since 1.6
     */
    @Nonnull
    public Iterable<Repository> getAdditionalRepositoriesFor(@Nonnull MavenProject project) throws MojoExecutionException {
        return emptyList();
    }

    /**
     * Returns each compile source root of a given <code>MavenProject</code> as a <code>Repository</code> instance
     * providing access to the Java files it contains.
     * Silently ignores compile source roots that do not exist in the file system.
     *
     * @since 1.6
     */
    @Nonnull
    protected Collection<Repository> getJavaFilesOfCompileSourceRootsAsRepositories(@Nonnull MavenProject project) {
        List<String> compileSourceRoots = project.getCompileSourceRoots();
        if (compileSourceRoots == null) {
            return emptyList();
        }

        Collection<Repository> codeRepositories = newArrayList();
        for (String compileSourceRoot : compileSourceRoots) {
            File compileSourceDirectory = new File(compileSourceRoot);
            if (!compileSourceDirectory.exists()) {
                logger.debug("  Compile Source Directory [{}] does not exist?", compileSourceDirectory);
                continue;
            }
            codeRepositories.add(new Repository(compileSourceDirectory,
                    new OrFileFilter(DIRECTORY, new RegexFileFilter(".*\\.java$", INSENSITIVE))));
            logger.debug("  Found source directory [{}].", compileSourceRoot);
        }
        return codeRepositories;
    }

}

@@ -474,31 +474,8 @@
 ion;
-%0Aimport java.util.List;
 %0A%0Aim
@@ -528,24 +528,76 @@
 wArrayList;%0A
+import static de.is24.deadcode4j.Utils.emptyIfNull;%0A
 import stati
@@ -2081,168 +2081,8 @@
 ) %7B%0A
-        List%3CString%3E compileSourceRoots = project.getCompileSourceRoots();%0A        if (compileSourceRoots == null) %7B%0A            return emptyList();%0A        %7D%0A%0A
     
@@ -2183,17 +2183,40 @@
 eRoot : 
-c
+emptyIfNull(project.getC
 ompileSo
@@ -2224,16 +2224,19 @@
 rceRoots
+())
 ) %7B%0A    

use emptyIfNull