// Path: src/main/java/com/sourcegraph/javagraph/PathUtil.java
// public class PathUtil {
// 
//     /**
//      * Current working directory
//      */
//     public static Path CWD = SystemUtils.getUserDir().toPath().toAbsolutePath().normalize();
// 
//     private PathUtil() {
//     }
// 
//     /**
//      * Normalizes path string by translating it to Unix-style (foo\bar => foo/bar)
//      * @param path path to normalize
//      * @return normalized path
//      */
//     public static String normalize(String path) {
//         if (SystemUtils.IS_OS_WINDOWS) {
//             return path.replace('\\', '/');
//         } else {
//             return path;
//         }
//     }
// 
//     /**
//      * Produces path relative to current working directory
//      * @param path path to process
//      * @return path translated relative to current directory, if path is located inside current directory or
//      * absolute path otherwise. For example, for path /foo/bar/baz and CWD /foo/bar result will be bar;
//      * for path /foo/bar/baz and CWD /kaboom/bar result will be /foo/bar/baz
//      */
//     public static String relativizeCwd(String path) {
//         return relativizeCwd(CWD.resolve(path).toAbsolutePath());
//     }
// 
//     /**
//      * Produces path relative to current working directory
//      * @param p path to process
//      * @return path translated relative to current directory, if path is located inside current directory or
//      * absolute path otherwise. For example, for path /foo/bar/baz and CWD /foo/bar result will be bar;
//      * for path /foo/bar/baz and CWD /kaboom/bar result will be /foo/bar/baz
//      */
//     public static String relativizeCwd(Path p) {
//         if (p.startsWith(CWD)) {
//             Path rel = CWD.relativize(p);
//             if (rel.toString().isEmpty()) {
//                 return StringUtils.EMPTY;
//             }
//             return normalize(rel.normalize().toString());
//         } else {
//             // for example, Android projects may refer to a directory on other drive
//             return normalize(p.normalize().toString());
//         }
//     }
// 
//     /**
//      * Concatenates two paths
//      * @param parent parent path
//      * @param child child path
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static Path concat(Path parent, Path child) {
//         if (child.isAbsolute()) {
//             return child;
//         } else {
//             return parent.resolve(child);
//         }
//     }
// 
//     /**
//      * Concatenates two paths
//      * @param parent parent path
//      * @param child child path
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static Path concat(Path parent, String child) {
//         return concat(parent, Paths.get(child));
//     }
// 
//     /**
//      * Concatenates two files
//      * @param parent parent file
//      * @param child child file
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static File concat(File parent, File child) {
//         if (child.isAbsolute()) {
//             return child;
//         } else {
//             return new File(parent, child.getPath());
//         }
//     }
// 
//     /**
//      * Concatenates two files
//      * @param parent parent file
//      * @param child child file
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static File concat(File parent, String child) {
//         return concat(parent, new File(child));
//     }
// 
// 
// }


import com.sourcegraph.javagraph.PathUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
    public void apply(MavenProject project,
                      File repoDir) {
        // Let's create generated source file such as R.java, BuildConfig.java and AIDL-based ones
        runMavenGoal(project.getModel().getPomFile(), repoDir, "generate-sources");
        String sourceRoot = getGeneratedSourceDirectory(project);
        LOGGER.debug("Registering source root {}", sourceRoot);
        project.getCompileSourceRoots().add(sourceRoot);
        project.getProperties().setProperty(com.sourcegraph.javagraph.MavenProject.ANDROID_PROPERTY, StringUtils.EMPTY);
    }

    /**
     *
     * @param project Maven project
     * @return project's generated sources directory
     */
    private String getGeneratedSourceDirectory(MavenProject project) {
        String genDirectory = project.getProperties().getProperty("android.genDirectory");
        if (genDirectory == null) {
            return getDefaultGeneratedSourceDirectory(project);
        } else {
            return PathUtil.concat(project.getModel().getProjectDirectory(), genDirectory).toString();
        }
    }

    /**
     *
     * @param project Maven project
     * @return project's default generated sources directory
     */
    private static String getDefaultGeneratedSourceDirectory(MavenProject project) {
// Path: src/main/java/com/sourcegraph/javagraph/PathUtil.java
// public class PathUtil {
// 
//     /**
//      * Current working directory
//      */
//     public static Path CWD = SystemUtils.getUserDir().toPath().toAbsolutePath().normalize();
// 
//     private PathUtil() {
//     }
// 
//     /**
//      * Normalizes path string by translating it to Unix-style (foo\bar => foo/bar)
//      * @param path path to normalize
//      * @return normalized path
//      */
//     public static String normalize(String path) {
//         if (SystemUtils.IS_OS_WINDOWS) {
//             return path.replace('\\', '/');
//         } else {
//             return path;
//         }
//     }
// 
//     /**
//      * Produces path relative to current working directory
//      * @param path path to process
//      * @return path translated relative to current directory, if path is located inside current directory or
//      * absolute path otherwise. For example, for path /foo/bar/baz and CWD /foo/bar result will be bar;
//      * for path /foo/bar/baz and CWD /kaboom/bar result will be /foo/bar/baz
//      */
//     public static String relativizeCwd(String path) {
//         return relativizeCwd(CWD.resolve(path).toAbsolutePath());
//     }
// 
//     /**
//      * Produces path relative to current working directory
//      * @param p path to process
//      * @return path translated relative to current directory, if path is located inside current directory or
//      * absolute path otherwise. For example, for path /foo/bar/baz and CWD /foo/bar result will be bar;
//      * for path /foo/bar/baz and CWD /kaboom/bar result will be /foo/bar/baz
//      */
//     public static String relativizeCwd(Path p) {
//         if (p.startsWith(CWD)) {
//             Path rel = CWD.relativize(p);
//             if (rel.toString().isEmpty()) {
//                 return StringUtils.EMPTY;
//             }
//             return normalize(rel.normalize().toString());
//         } else {
//             // for example, Android projects may refer to a directory on other drive
//             return normalize(p.normalize().toString());
//         }
//     }
// 
//     /**
//      * Concatenates two paths
//      * @param parent parent path
//      * @param child child path
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static Path concat(Path parent, Path child) {
//         if (child.isAbsolute()) {
//             return child;
//         } else {
//             return parent.resolve(child);
//         }
//     }
// 
//     /**
//      * Concatenates two paths
//      * @param parent parent path
//      * @param child child path
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static Path concat(Path parent, String child) {
//         return concat(parent, Paths.get(child));
//     }
// 
//     /**
//      * Concatenates two files
//      * @param parent parent file
//      * @param child child file
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static File concat(File parent, File child) {
//         if (child.isAbsolute()) {
//             return child;
//         } else {
//             return new File(parent, child.getPath());
//         }
//     }
// 
//     /**
//      * Concatenates two files
//      * @param parent parent file
//      * @param child child file
//      * @return child resolved to parent if child is not absolute, child otherwise
//      */
//     public static File concat(File parent, String child) {
//         return concat(parent, new File(child));
//     }
// 
// 
// }


// Path: src/main/java/com/sourcegraph/javagraph/maven/plugins/SimpligilityAndroidMavenPlugin.java
import com.sourcegraph.javagraph.PathUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;

    public void apply(MavenProject project,
                      File repoDir) {
        // Let's create generated source file such as R.java, BuildConfig.java and AIDL-based ones
        runMavenGoal(project.getModel().getPomFile(), repoDir, "generate-sources");
        String sourceRoot = getGeneratedSourceDirectory(project);
        LOGGER.debug("Registering source root {}", sourceRoot);
        project.getCompileSourceRoots().add(sourceRoot);
        project.getProperties().setProperty(com.sourcegraph.javagraph.MavenProject.ANDROID_PROPERTY, StringUtils.EMPTY);
    }

    /**
     *
     * @param project Maven project
     * @return project's generated sources directory
     */
    private String getGeneratedSourceDirectory(MavenProject project) {
        String genDirectory = project.getProperties().getProperty("android.genDirectory");
        if (genDirectory == null) {
            return getDefaultGeneratedSourceDirectory(project);
        } else {
            return PathUtil.concat(project.getModel().getProjectDirectory(), genDirectory).toString();
        }
    }

    /**
     *
     * @param project Maven project
     * @return project's default generated sources directory
     */
    private static String getDefaultGeneratedSourceDirectory(MavenProject project) {
        File root = PathUtil.concat(project.getModel().getProjectDirectory(), project.getBuild().getDirectory());