Search in sources :

Example 1 with ClasspathResult

use of org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult in project eclipse.jdt.ls by eclipse.

the class ProjectCommandTest method testGetClasspathsForMaven.

@Test
public void testGetClasspathsForMaven() throws Exception {
    importProjects("maven/classpathtest");
    IProject project = WorkspaceHelper.getProject("classpathtest");
    String uriString = project.getFile("src/main/java/main/App.java").getLocationURI().toString();
    ClasspathOptions options = new ClasspathOptions();
    options.scope = "runtime";
    ClasspathResult result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(1, result.classpaths.length);
    assertEquals(0, result.modulepaths.length);
    assertTrue(result.classpaths[0].indexOf("junit") == -1);
    options.scope = "test";
    result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(4, result.classpaths.length);
    assertEquals(0, result.modulepaths.length);
    boolean containsJunit = Arrays.stream(result.classpaths).anyMatch(element -> {
        return element.indexOf("junit") > -1;
    });
    assertTrue(containsJunit);
}
Also used : ClasspathResult(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult) IProject(org.eclipse.core.resources.IProject) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 2 with ClasspathResult

use of org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult in project eclipse.jdt.ls by eclipse.

the class ProjectCommandTest method testGetClasspathsForMavenModular.

@Test
public void testGetClasspathsForMavenModular() throws Exception {
    importProjects("maven/modular-project");
    IProject project = WorkspaceHelper.getProject("modular-project");
    String uriString = project.getFile("src/main/java/modular/Main.java").getLocationURI().toString();
    ClasspathOptions options = new ClasspathOptions();
    options.scope = "test";
    ClasspathResult result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(0, result.classpaths.length);
    assertEquals(1, result.modulepaths.length);
}
Also used : ClasspathResult(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult) IProject(org.eclipse.core.resources.IProject) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 3 with ClasspathResult

use of org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult in project eclipse.jdt.ls by eclipse.

the class ProjectCommandTest method testGetClasspathsForMavenWhenUpdating.

@Test
public void testGetClasspathsForMavenWhenUpdating() throws Exception {
    importProjects("maven/classpathtest");
    IProject project = WorkspaceHelper.getProject("classpathtest");
    String uriString = project.getFile("src/main/java/main/App.java").getLocationURI().toString();
    ClasspathOptions options = new ClasspathOptions();
    options.scope = "test";
    projectsManager.updateProject(project, true);
    for (int i = 0; i < 10; i++) {
        ClasspathResult result = ProjectCommand.getClasspaths(uriString, options);
        assertEquals(4, result.classpaths.length);
        assertEquals(0, result.modulepaths.length);
        boolean containsJunit = Arrays.stream(result.classpaths).anyMatch(element -> {
            return element.indexOf("junit") > -1;
        });
        assertTrue(containsJunit);
    }
}
Also used : ClasspathResult(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult) IProject(org.eclipse.core.resources.IProject) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 4 with ClasspathResult

use of org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult in project eclipse.jdt.ls by eclipse.

the class ProjectCommandTest method testGetClasspathsForGradle.

@Test
public void testGetClasspathsForGradle() throws Exception {
    importProjects("gradle/simple-gradle");
    IProject project = WorkspaceHelper.getProject("simple-gradle");
    String uriString = project.getFile("src/main/java/Library.java").getLocationURI().toString();
    ClasspathOptions options = new ClasspathOptions();
    // Gradle project will always return classpath containing test dependencies.
    // So we only test `scope = "test"` scenario.
    options.scope = "test";
    ClasspathResult result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(5, result.classpaths.length);
    assertEquals(0, result.modulepaths.length);
    boolean containsJunit = Arrays.stream(result.classpaths).anyMatch(element -> {
        return element.indexOf("junit") > -1;
    });
    assertTrue(containsJunit);
}
Also used : ClasspathResult(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult) IProject(org.eclipse.core.resources.IProject) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 5 with ClasspathResult

use of org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult in project eclipse.jdt.ls by eclipse.

the class ProjectCommandTest method testGetClasspathsForEclipse.

@Test
public void testGetClasspathsForEclipse() throws Exception {
    importProjects("eclipse/hello");
    IProject project = WorkspaceHelper.getProject("hello");
    String uriString = project.getFile("src/java/Bar.java").getLocationURI().toString();
    ClasspathOptions options = new ClasspathOptions();
    options.scope = "runtime";
    ClasspathResult result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(1, result.classpaths.length);
    assertEquals(0, result.modulepaths.length);
    options.scope = "test";
    result = ProjectCommand.getClasspaths(uriString, options);
    assertEquals(2, result.classpaths.length);
    assertEquals(0, result.modulepaths.length);
}
Also used : ClasspathResult(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult) IProject(org.eclipse.core.resources.IProject) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Aggregations

IProject (org.eclipse.core.resources.IProject)5 ClasspathOptions (org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions)5 ClasspathResult (org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathResult)5 AbstractInvisibleProjectBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)5 Test (org.junit.Test)5