use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult 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);
}
use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult 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());
}
use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult 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);
}
use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult in project eclipse.jdt.ls by eclipse.
the class FileEventHandler method getSourcePaths.
private static SourcePath[] getSourcePaths() {
SourcePath[] sourcePaths = new SourcePath[0];
ListCommandResult result = (ListCommandResult) BuildPathCommand.listSourcePaths();
if (result.status && result.data != null && result.data.length > 0) {
sourcePaths = result.data;
}
Arrays.sort(sourcePaths, (a, b) -> {
return b.path.length() - a.path.length();
});
return sourcePaths;
}
use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.ListCommandResult 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);
}
Aggregations