use of org.eclipse.jdt.ls.core.internal.ResourceUtils in project eclipse.jdt.ls by eclipse.
the class AbstractProjectsManagerBasedTest method assertHasErrors.
protected void assertHasErrors(IProject project, String... expectedErrorsLike) {
try {
List<IMarker> markers = ResourceUtils.getErrorMarkers(project);
String allErrors = ResourceUtils.toString(markers);
for (String expectedError : expectedErrorsLike) {
boolean hasError = markers.stream().map(ResourceUtils::getMessage).filter(Objects::nonNull).filter(m -> m.contains(expectedError)).findFirst().isPresent();
assertTrue(expectedError + " was not found in: \n" + allErrors, hasError);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.jdt.ls.core.internal.ResourceUtils in project eclipse.jdt.ls by eclipse.
the class StandardProjectsManager method registerWatchers.
@Override
public List<FileSystemWatcher> registerWatchers() {
logInfo(">> registerWatchers'");
if (preferenceManager.getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) {
Set<String> patterns = new LinkedHashSet<>(basicWatchers);
buildSupports().forEach(e -> e.getWatchPatterns().forEach(patterns::add));
Set<IPath> sources = new HashSet<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
try {
for (IProject project : projects) {
if (DEFAULT_PROJECT_NAME.equals(project.getName())) {
continue;
}
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null && javaProject.exists()) {
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (IClasspathEntry entry : classpath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath path = entry.getPath();
if (path != null && !path.toString().contains("/src/") && !path.toString().endsWith("/src")) {
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
if (folder.exists() && !folder.isDerived()) {
IPath location = folder.getLocation();
if (location != null && !isContainedIn(location, sources)) {
sources.add(location);
}
}
}
}
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (resource != null && !resource.isDerived()) {
IPath location = resource.getLocation();
if (location != null && !isContainedIn(location, sources)) {
sources.add(location);
}
}
}
}
if (!ProjectUtils.isVisibleProject(project)) {
// Invisible project will watch referenced libraries' include patterns
IPath projectFolder = ProjectUtils.getProjectRealFolder(project);
Set<String> libraries = preferenceManager.getPreferences().getReferencedLibraries().getInclude();
for (String pattern : libraries) {
patterns.add(ProjectUtils.resolveGlobPath(projectFolder, pattern).toPortableString());
}
patterns.add("**/.settings");
}
}
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
List<FileSystemWatcher> fileWatchers = new ArrayList<>();
patterns.addAll(sources.stream().map(ResourceUtils::toGlobPattern).collect(Collectors.toList()));
sources.clear();
URI formatter = preferenceManager.getPreferences().getFormatterAsURI();
if (formatter == null && preferenceManager.getPreferences().getFormatterUrl() != null) {
List<URI> uris = getURIs(preferenceManager.getPreferences().getFormatterUrl());
for (URI uri : uris) {
addWatcher(uri, sources);
}
} else {
addWatcher(formatter, sources);
}
URI settings = preferenceManager.getPreferences().getSettingsAsURI();
if (settings == null && preferenceManager.getPreferences().getSettingsUrl() != null) {
List<URI> uris = getURIs(preferenceManager.getPreferences().getSettingsUrl());
for (URI uri : uris) {
addWatcher(uri, sources);
}
} else {
addWatcher(settings, sources);
}
patterns.addAll(sources.stream().map(p -> ResourceUtils.toGlobPattern(p, false)).collect(Collectors.toList()));
for (String pattern : patterns) {
FileSystemWatcher watcher = new FileSystemWatcher(pattern);
fileWatchers.add(watcher);
}
// Watch on project root folders.
for (IProject project : projects) {
if (ProjectUtils.isVisibleProject(project) && project.exists()) {
FileSystemWatcher watcher = new FileSystemWatcher(ResourceUtils.toGlobPattern(project.getLocation(), false), WatchKind.Delete);
fileWatchers.add(watcher);
}
}
if (!patterns.equals(watchers)) {
logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
DidChangeWatchedFilesRegistrationOptions didChangeWatchedFilesRegistrationOptions = new DidChangeWatchedFilesRegistrationOptions(fileWatchers);
JavaLanguageServerPlugin.getInstance().unregisterCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES);
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES, didChangeWatchedFilesRegistrationOptions);
watchers.clear();
watchers.addAll(patterns);
}
return fileWatchers;
}
return Collections.emptyList();
}
use of org.eclipse.jdt.ls.core.internal.ResourceUtils in project eclipse.jdt.ls by eclipse.
the class SyntaxProjectsManager method registerWatchers.
@Override
public List<FileSystemWatcher> registerWatchers() {
logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
if (JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) {
IPath[] sources = new IPath[0];
try {
sources = listAllSourcePaths();
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
List<FileSystemWatcher> fileWatchers = new ArrayList<>();
Set<String> patterns = new LinkedHashSet<>(basicWatchers);
patterns.addAll(Stream.of(sources).map(ResourceUtils::toGlobPattern).collect(Collectors.toList()));
for (String pattern : patterns) {
FileSystemWatcher watcher = new FileSystemWatcher(pattern);
fileWatchers.add(watcher);
}
if (!patterns.equals(watchers)) {
JavaLanguageServerPlugin.logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
DidChangeWatchedFilesRegistrationOptions didChangeWatchedFilesRegistrationOptions = new DidChangeWatchedFilesRegistrationOptions(fileWatchers);
JavaLanguageServerPlugin.getInstance().unregisterCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES);
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES, didChangeWatchedFilesRegistrationOptions);
watchers.clear();
watchers.addAll(patterns);
}
return fileWatchers;
}
return Collections.emptyList();
}
Aggregations