use of org.eclipse.jdt.ls.core.internal.commands.BuildPathCommand.SourcePath 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.SourcePath 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.SourcePath 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.SourcePath 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.SourcePath in project eclipse.jdt.ls by eclipse.
the class FileEventHandler method resolvePackage.
private static Object resolvePackage(IPath javaElementLocation, SourcePath[] sourcePaths, boolean returnModel) {
for (SourcePath sourcePath : sourcePaths) {
IPath sourceLocation = Path.fromOSString(sourcePath.path);
IPath sourceEntry = Path.fromOSString(sourcePath.classpathEntry);
if (sourceLocation.isPrefixOf(javaElementLocation)) {
try {
IJavaProject javaProject = ProjectUtils.getJavaProject(sourcePath.projectName);
if (javaProject == null) {
return null;
}
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(sourceEntry);
if (packageRoot == null) {
return null;
}
String packageName = String.join(".", javaElementLocation.makeRelativeTo(sourceLocation).segments());
if (returnModel) {
return packageRoot.getPackageFragment(packageName);
}
return packageName;
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Failed to resolve the package fragment", e);
}
return null;
}
}
return null;
}
Aggregations