private IPath inferSourceDirectory(java.nio.file.Path filePath, String packageName) { String packagePath = packageName.replace(JDTUtils.PERIOD, JDTUtils.PATH_SEPARATOR); java.nio.file.Path sourcePath = filePath.getParent(); if (StringUtils.isBlank(packagePath)) { return ResourceUtils.filePathFromURI(sourcePath.toUri().toString()); } else if (sourcePath.endsWith(Paths.get(packagePath))) { // package should match ancestor folders. int packageCount = packageName.split("\\" + JDTUtils.PERIOD).length; while (packageCount > 0) { sourcePath = sourcePath.getParent(); packageCount--; } return ResourceUtils.filePathFromURI(sourcePath.toUri().toString()); } return null; } }
private List<TextEdit> handleSaveActionOrganizeImports(String documentUri, IProgressMonitor monitor) { String uri = ResourceUtils.fixURI(JDTUtils.toURI(documentUri)); if (monitor.isCanceled()) { return Collections.emptyList(); } WorkspaceEdit organizedResult = organizeImportsCommand.organizeImportsInFile(uri); List<TextEdit> edit = organizedResult.getChanges().get(uri); edit = edit == null ? Collections.emptyList() : edit; return edit; }
public Preferences setMavenUserSettings(String mavenUserSettings) { this.mavenUserSettings = ResourceUtils.expandPath(mavenUserSettings); return this; }
public static boolean isVisibleProject(IProject project) { PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager(); Collection<IPath> rootPaths = manager.getPreferences().getRootPaths(); if (rootPaths == null) { return false; } return ResourceUtils.isContainedIn(project.getLocation(), rootPaths); }
public URL getUrl(String formatterUrl) { URL url = null; try { url = new URL(ResourceUtils.toClientUri(formatterUrl)); } catch (MalformedURLException e1) { File file = findFile(formatterUrl); if (file != null && file.isFile()) { try { url = file.toURI().toURL(); } catch (MalformedURLException e) { JavaLanguageServerPlugin.logInfo("Invalid formatter:" + formatterUrl); } } } return url; }
if (!project.equals(projectsManager.getDefaultProject())) { String uri = JDTUtils.getFileURI(project); connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList())); for (IProject project : projects) { if (!project.equals(projectsManager.getDefaultProject())) { List<IMarker> markers = ResourceUtils.getErrorMarkers(project); if (markers != null) { problemMarkers.addAll(markers);
/** * Writes content to file, outside the workspace. No change event is * emitted. */ public static void setContent(URI fileURI, String content) throws CoreException { if (content == null) { content = ""; } try { Files.write(content, toFile(fileURI), Charsets.UTF_8); } catch (IOException e) { throw new CoreException(StatusFactory.newErrorStatus("Can not write to " + fileURI, e)); } }
public static List<IMarker> getWarningMarkers(IResource resource) throws CoreException { return findMarkers(resource, IMarker.SEVERITY_WARNING); }
public void update(DidChangeWorkspaceFoldersParams params) { final Collection<IPath> addedRootPaths = new ArrayList<>(); final Collection<IPath> removedRootPaths = new ArrayList<>(); for (WorkspaceFolder folder : params.getEvent().getAdded()) { IPath rootPath = ResourceUtils.canonicalFilePathFromURI(folder.getUri()); if (rootPath != null) { addedRootPaths.add(rootPath); } } for (WorkspaceFolder folder : params.getEvent().getRemoved()) { IPath rootPath = ResourceUtils.canonicalFilePathFromURI(folder.getUri()); if (rootPath != null) { removedRootPaths.add(rootPath); } } projectManager.updateWorkspaceFolders(addedRootPaths, removedRootPaths); } }
public static String toString(List<IMarker> markers) { if (markers == null || markers.isEmpty()) { return ""; } String s = markers.stream().map(m -> toString(m)).collect(Collectors.joining(", ")); return s; }
IProject[] projects = getWorkspaceRoot().getProjects(); for (IProject project : projects) { if (ResourceUtils.isContainedIn(project.getLocation(), removedRootPaths)) { try { project.delete(false, true, subMonitor.split(1));
public void clearDiagnostics() { JavaLanguageServerPlugin.logInfo("Clearing problems for " + this.uri.substring(this.uri.lastIndexOf('/'))); problems.clear(); PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList()); this.connection.publishDiagnostics($); }
/** * Reads file content directly from the filesystem. */ public static String getContent(URI fileURI) throws CoreException { if (fileURI == null) { return null; } String content; try { content = Files.toString(toFile(fileURI), Charsets.UTF_8); } catch (IOException e) { throw new CoreException(StatusFactory.newErrorStatus("Can not get " + fileURI + " content", e)); } return content; }
public static List<IMarker> getErrorMarkers(IResource resource) throws CoreException { return findMarkers(resource, IMarker.SEVERITY_ERROR); }
if (workspaceFolders != null && !workspaceFolders.isEmpty()) { for (String uri : workspaceFolders) { IPath filePath = ResourceUtils.canonicalFilePathFromURI(uri); if (filePath != null) { rootPaths.add(filePath); IPath filePath = ResourceUtils.canonicalFilePathFromURI(rootPath); if (filePath != null) { rootPaths.add(filePath); if (triggerFiles != null) { for (String uri : triggerFiles) { IPath filePath = ResourceUtils.canonicalFilePathFromURI(uri); if (filePath != null) { triggerPaths.add(filePath);
@Override public boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException { IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toPath().toUri().toString()); if (workspaceLocation.equals(rootPath)) { return false; } return ProjectUtils.getVisibleProjects(rootPath).isEmpty(); }
/** * Returns uri for a resource * @param resource * @return */ public static String getFileURI(IResource resource) { return ResourceUtils.fixURI(resource.getRawLocationURI() == null ? resource.getLocationURI() : resource.getRawLocationURI()); }
private void deleteInvalidProjects(Collection<IPath> rootPaths, IProgressMonitor monitor) { List<String> workspaceProjects = rootPaths.stream().map((IPath rootPath) -> ProjectUtils.getWorkspaceInvisibleProjectName(rootPath)).collect(Collectors.toList()); for (IProject project : getWorkspaceRoot().getProjects()) { if (project.exists() && (ResourceUtils.isContainedIn(project.getLocation(), rootPaths) || ProjectUtils.isGradleProject(project)) || workspaceProjects.contains(project.getName())) { try { project.getDescription(); } catch (CoreException e) { try { project.delete(true, monitor); } catch (CoreException e1) { JavaLanguageServerPlugin.logException(e1.getMessage(), e1); } } } else { try { project.delete(false, true, monitor); } catch (CoreException e1) { JavaLanguageServerPlugin.logException(e1.getMessage(), e1); } } } }
private void cleanUpDiagnostics(String uri){ this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList())); }
public static String getPackageName(IJavaProject javaProject, URI uri) { try { File file = ResourceUtils.toFile(uri); //FIXME need to determine actual charset from file String content = Files.toString(file, Charsets.UTF_8); if (content.isEmpty() && javaProject != null && ProjectsManager.DEFAULT_PROJECT_NAME.equals(javaProject.getProject().getName())) { java.nio.file.Path path = Paths.get(uri); java.nio.file.Path parent = path; while (parent.getParent() != null && parent.getParent().getNameCount() > 0) { parent = parent.getParent(); String name = parent.getName(parent.getNameCount() - 1).toString(); if (SRC.equals(name)) { String pathStr = path.getParent().toString(); if (pathStr.length() > parent.toString().length()) { pathStr = pathStr.substring(parent.toString().length() + 1); pathStr = pathStr.replace(PATH_SEPARATOR, PERIOD); return pathStr; } } } } else { return getPackageName(javaProject, content); } } catch (IOException e) { JavaLanguageServerPlugin.logException("Failed to read package name from "+uri, e); } return ""; }