Search in sources :

Example 1 with Result

use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result in project eclipse.jdt.ls by eclipse.

the class BuildPathCommandTest method testBuildPathOperationInMavenProject.

@Test
public void testBuildPathOperationInMavenProject() throws Exception {
    importProjects("maven/salut");
    IProject project = WorkspaceHelper.getProject("salut");
    PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager();
    manager.getPreferences().setRootPaths(Arrays.asList(project.getLocation()));
    ListCommandResult listResult = (ListCommandResult) BuildPathCommand.listSourcePaths();
    assertTrue(listResult.status);
    SourcePath[] sourcePaths = listResult.data;
    assertNotNull(sourcePaths);
    assertEquals(sourcePaths.length, 5);
    IResource srcResource = project.findMember("src");
    Result addSrcResult = BuildPathCommand.addToSourcePath(JDTUtils.getFileURI(srcResource));
    assertFalse(addSrcResult.status);
    assertEquals(addSrcResult.message, MavenBuildSupport.UNSUPPORTED_ON_MAVEN);
    IResource mainJavaResource = project.findMember("src/main/java");
    Result addMainJavaResult = BuildPathCommand.removeFromSourcePath(JDTUtils.getFileURI(mainJavaResource));
    assertFalse(addMainJavaResult.status);
    assertEquals(addMainJavaResult.message, MavenBuildSupport.UNSUPPORTED_ON_MAVEN);
}
Also used : SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Result(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 2 with Result

use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result in project eclipse.jdt.ls by eclipse.

the class BuildPathCommandTest method testBuildPathOperationInWorkspaceProject.

@Test
public void testBuildPathOperationInWorkspaceProject() throws IOException {
    String path = "singlefile/lesson1";
    File file = copyFiles(path, true);
    IPath workspaceRoot = Path.fromOSString(file.getAbsolutePath());
    PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager();
    manager.getPreferences().setRootPaths(Arrays.asList(workspaceRoot));
    IPath srcPath = workspaceRoot.append("src");
    Result addSrcResult = BuildPathCommand.addToSourcePath(srcPath.toFile().toURI().toString());
    assertTrue(addSrcResult.status);
    String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspaceRoot);
    IProject invisibleProject = ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName);
    assertTrue(invisibleProject.exists());
    assertTrue(ProjectUtils.isJavaProject(invisibleProject));
    IPath mainJavaPath = workspaceRoot.append("src/main/java");
    Result addMainJavaResult = BuildPathCommand.addToSourcePath(mainJavaPath.toFile().toURI().toString());
    assertFalse(addMainJavaResult.status);
    IPath samplesPath = workspaceRoot.append("samples");
    Result addSamplesResult = BuildPathCommand.addToSourcePath(samplesPath.toFile().toURI().toString());
    assertTrue(addSamplesResult.status);
    ListCommandResult listResult = (ListCommandResult) BuildPathCommand.listSourcePaths();
    assertTrue(listResult.status);
    SourcePath[] sourcePaths = listResult.data;
    assertNotNull(sourcePaths);
    assertEquals(sourcePaths.length, 2);
    assertEquals(sourcePaths[0].displayPath, new Path("lesson1").append("src").toOSString());
    assertEquals(sourcePaths[1].displayPath, new Path("lesson1").append("samples").toOSString());
}
Also used : SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) IPath(org.eclipse.core.runtime.IPath) SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) Path(org.eclipse.core.runtime.Path) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) IPath(org.eclipse.core.runtime.IPath) File(java.io.File) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) IProject(org.eclipse.core.resources.IProject) Result(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 3 with Result

use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result in project eclipse.jdt.ls by eclipse.

the class BuildPathCommandTest method testBuildPathOperationInGradleProject.

@Test
public void testBuildPathOperationInGradleProject() throws Exception {
    importProjects("gradle/simple-gradle");
    IProject project = WorkspaceHelper.getProject("simple-gradle");
    PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager();
    manager.getPreferences().setRootPaths(Arrays.asList(project.getLocation()));
    ListCommandResult listResult = (ListCommandResult) BuildPathCommand.listSourcePaths();
    assertTrue(listResult.status);
    SourcePath[] sourcePaths = listResult.data;
    assertNotNull(sourcePaths);
    assertEquals(sourcePaths.length, 2);
    IResource srcResource = project.findMember("src");
    Result addSrcResult = BuildPathCommand.addToSourcePath(JDTUtils.getFileURI(srcResource));
    assertFalse(addSrcResult.status);
    assertEquals(addSrcResult.message, GradleBuildSupport.UNSUPPORTED_ON_GRADLE);
    IResource mainJavaResource = project.findMember("src/main/java");
    Result addMainJavaResult = BuildPathCommand.removeFromSourcePath(JDTUtils.getFileURI(mainJavaResource));
    assertFalse(addMainJavaResult.status);
    assertEquals(addMainJavaResult.message, GradleBuildSupport.UNSUPPORTED_ON_GRADLE);
}
Also used : SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Result(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 4 with Result

use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result in project eclipse.jdt.ls by eclipse.

the class BuildPathCommandTest method testBuildPathOperationInEclipseProject.

@Test
public void testBuildPathOperationInEclipseProject() throws Exception {
    importProjects("eclipse/hello");
    IProject project = WorkspaceHelper.getProject("hello");
    PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager();
    manager.getPreferences().setRootPaths(Arrays.asList(project.getLocation()));
    ListCommandResult listResult = (ListCommandResult) BuildPathCommand.listSourcePaths();
    assertTrue(listResult.status);
    SourcePath[] sourcePaths = listResult.data;
    assertNotNull(sourcePaths);
    assertEquals(sourcePaths.length, 2);
    assertEquals(sourcePaths[0].displayPath, new Path("hello").append("src").toOSString());
    assertEquals(sourcePaths[1].displayPath, new Path("hello").append("test").toOSString());
    IResource srcJavaResource = project.findMember("src/java");
    Result addSrcJavaResult = BuildPathCommand.addToSourcePath(JDTUtils.getFileURI(srcJavaResource));
    assertFalse(addSrcJavaResult.status);
    IJavaProject javaProject = JavaCore.create(project);
    IResource nopackageResource = project.findMember("nopackage");
    Result addNopackageResult = BuildPathCommand.addToSourcePath(JDTUtils.getFileURI(nopackageResource));
    assertTrue(addNopackageResult.status);
    assertEquals(ProjectUtils.listSourcePaths(javaProject).length, 3);
    Result removeNopackageResult = BuildPathCommand.removeFromSourcePath(JDTUtils.getFileURI(nopackageResource));
    assertTrue(removeNopackageResult.status);
    assertEquals(ProjectUtils.listSourcePaths(javaProject).length, 2);
}
Also used : SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) IPath(org.eclipse.core.runtime.IPath) SourcePath(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath) Path(org.eclipse.core.runtime.Path) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) IJavaProject(org.eclipse.jdt.core.IJavaProject) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Result(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result) ListCommandResult(org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

IProject (org.eclipse.core.resources.IProject)4 ListCommandResult (org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult)4 Result (org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.Result)4 SourcePath (org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath)4 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 PreferenceManager (org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)4 Test (org.junit.Test)4 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 File (java.io.File)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1