// Path: me.gladwell.eclipse.m2e.android.test/src/me/gladwell/eclipse/m2e/android/test/Classpaths.java
// public final static Comparator<IClasspathEntry> bySourceFolderOrdering = new Comparator<IClasspathEntry>() {
// 
//     private final List<String> order = asList(new String[]{
//             "src/main/java",
//             "src/main/resources",
//             "gen",
//             "src/test/java",
//             "src/test/resources"
//     });
// 
//     @Override
//     public int compare(IClasspathEntry left, IClasspathEntry right) {
//         IPath lsegment = left.getPath().removeFirstSegments(1);
//         IPath rsegment = right.getPath().removeFirstSegments(1);
// 
//         int li = order.indexOf(lsegment.toString());
//         int ri = order.indexOf(rsegment.toString());
// 
//         int result;
// 
//         if(li < 0 || ri < 0) {
//             result = left.getEntryKind() - right.getEntryKind();
//         } else {
//             result = li - ri;
//         }
// 
//         return result;
//     }
// 
// };


import static java.util.Arrays.asList;
import static me.gladwell.eclipse.m2e.android.test.Classpaths.bySourceFolderOrdering;
import static org.eclipse.m2e.core.MavenPlugin.getProjectConfigurationManager;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.m2e.jdt.IClasspathManager;
    }

    public void testConfigureAddsWorkspaceLibraryInSubfdoler() throws Exception {
        File subfolder = new File(workspace.getRoot().getLocation().toFile(), "subfolder");
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME, subfolder);
        TestAndroidProject project = new TestAndroidProject(importAndroidProject(TEST_PROJECT_WITH_APKLIB_DEPS));

        assertTrue(project.libraries().contains(libraryProject));
    }

    public void testConfigureAddsWorkspaceLibraryOutsideWorkspaceFolder() throws Exception {
        File temp = createTempFolder();
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME, temp);
        TestAndroidProject project = new TestAndroidProject(importAndroidProject(TEST_PROJECT_WITH_APKLIB_DEPS));

        assertTrue(project.libraries().contains(libraryProject));
    }

    public void testConfigureDoesNotMarkMavenContainerExported() throws Exception {
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME);
        IJavaProject javaProject = JavaCore.create(libraryProject);
        IClasspathEntry mavenContainer = getClasspathContainer(javaProject, IClasspathManager.CONTAINER_ID);
        assertTrue(!mavenContainer.isExported());
    }

    public void testSourceFolderOrder() throws Exception {
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME);
        IJavaProject javaProject = JavaCore.create(libraryProject);
        IClasspathEntry[] rawClasspath = Arrays.copyOf(javaProject.getRawClasspath(), javaProject.getRawClasspath().length);
        List<IClasspathEntry> sorted = asList(rawClasspath);
// Path: me.gladwell.eclipse.m2e.android.test/src/me/gladwell/eclipse/m2e/android/test/Classpaths.java
// public final static Comparator<IClasspathEntry> bySourceFolderOrdering = new Comparator<IClasspathEntry>() {
// 
//     private final List<String> order = asList(new String[]{
//             "src/main/java",
//             "src/main/resources",
//             "gen",
//             "src/test/java",
//             "src/test/resources"
//     });
// 
//     @Override
//     public int compare(IClasspathEntry left, IClasspathEntry right) {
//         IPath lsegment = left.getPath().removeFirstSegments(1);
//         IPath rsegment = right.getPath().removeFirstSegments(1);
// 
//         int li = order.indexOf(lsegment.toString());
//         int ri = order.indexOf(rsegment.toString());
// 
//         int result;
// 
//         if(li < 0 || ri < 0) {
//             result = left.getEntryKind() - right.getEntryKind();
//         } else {
//             result = li - ri;
//         }
// 
//         return result;
//     }
// 
// };


// Path: me.gladwell.eclipse.m2e.android.test/src/me/gladwell/eclipse/m2e/android/test/LibraryAndroidMavenPluginTest.java
import static java.util.Arrays.asList;
import static me.gladwell.eclipse.m2e.android.test.Classpaths.bySourceFolderOrdering;
import static org.eclipse.m2e.core.MavenPlugin.getProjectConfigurationManager;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.m2e.jdt.IClasspathManager;

    }

    public void testConfigureAddsWorkspaceLibraryInSubfdoler() throws Exception {
        File subfolder = new File(workspace.getRoot().getLocation().toFile(), "subfolder");
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME, subfolder);
        TestAndroidProject project = new TestAndroidProject(importAndroidProject(TEST_PROJECT_WITH_APKLIB_DEPS));

        assertTrue(project.libraries().contains(libraryProject));
    }

    public void testConfigureAddsWorkspaceLibraryOutsideWorkspaceFolder() throws Exception {
        File temp = createTempFolder();
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME, temp);
        TestAndroidProject project = new TestAndroidProject(importAndroidProject(TEST_PROJECT_WITH_APKLIB_DEPS));

        assertTrue(project.libraries().contains(libraryProject));
    }

    public void testConfigureDoesNotMarkMavenContainerExported() throws Exception {
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME);
        IJavaProject javaProject = JavaCore.create(libraryProject);
        IClasspathEntry mavenContainer = getClasspathContainer(javaProject, IClasspathManager.CONTAINER_ID);
        assertTrue(!mavenContainer.isExported());
    }

    public void testSourceFolderOrder() throws Exception {
        IProject libraryProject = importAndroidProject(ANDROID_LIB_PROJECT_NAME);
        IJavaProject javaProject = JavaCore.create(libraryProject);
        IClasspathEntry[] rawClasspath = Arrays.copyOf(javaProject.getRawClasspath(), javaProject.getRawClasspath().length);
        List<IClasspathEntry> sorted = asList(rawClasspath);
        Collections.sort(sorted, bySourceFolderOrdering);