@Override public void elementChanged(ElementChangedEvent event) { final Set<IProject> projects = getAffectedProjects(event.getDelta(), new HashSet<IProject>()); if (projects.isEmpty()) { return; } try { final Set<String> projectLocations = new HashSet<String>(); for (final IProject project : projects) { projectLocations.add(ResourceUtils.fixURI(project.getLocationURI())); } final JDTLanguageServer ls = JavaLanguageServerPlugin.getInstance().getProtocol(); ls.getClientConnection().sendNotification(CLIENT_UPDATE_CLASSPATH, (Object[]) projectLocations.toArray(new String[projectLocations.size()])); } catch (final Exception e) { // Ignore. JavaLanguageServerPlugin.logException("An exception occured while reporting project CLASSPATH change", e); } }
@Override public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); try { Platform.getBundle(ResourcesPlugin.PI_RESOURCES).start(Bundle.START_TRANSIENT); } catch (BundleException e) { logException(e.getMessage(), e); } try { redirectStandardStreams(); } catch (FileNotFoundException e) { logException(e.getMessage(), e); } JavaLanguageServerPlugin.context = bundleContext; JavaLanguageServerPlugin.pluginInstance = this; setPreferenceNodeId(); preferenceManager = new PreferenceManager(); digestStore = new DigestStore(getStateLocation().toFile()); projectsManager = new ProjectsManager(preferenceManager); try { ResourcesPlugin.getWorkspace().addSaveParticipant(IConstants.PLUGIN_ID, projectsManager); } catch (CoreException e) { logException(e.getMessage(), e); } contentProviderManager = new ContentProviderManager(preferenceManager); logInfo(getClass() + " is started"); configureProxy(); }
/** * @param array */ private static IStatus startBundles(Collection<Bundle> bundles) { final BundleContext context = JavaLanguageServerPlugin.getBundleContext(); MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Starting added bundles", null); for (Bundle bundle : bundles) { if (bundle.getState() == Bundle.UNINSTALLED) { status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Could not start: " + bundle.getSymbolicName() + '(' + bundle.getLocation() + ':' + bundle.getBundleId() + ')' + ". It's state is uninstalled.")); continue; } if (bundle.getState() == Bundle.STARTING) { continue; } if (bundle.getBundleId() == 0) { continue; } try { // set to the default value for osgi.bundles.defaultStartLevel bundle.adapt(BundleStartLevel.class).setStartLevel(4); bundle.start(Bundle.START_ACTIVATION_POLICY); JavaLanguageServerPlugin.logInfo("Started " + bundle.getLocation()); } catch (BundleException e) { status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Bundle startup failed " + bundle.getLocation(), e)); } } return status; }
public synchronized IDelegateCommandHandler getDelegateCommandHandler() { if (fDelegateCommandHandlerInstance == null) { try { Object extension = fConfigurationElement.createExecutableExtension(CLASS); if (extension instanceof IDelegateCommandHandler) { fDelegateCommandHandlerInstance = (IDelegateCommandHandler) extension; } else { String message = "Invalid extension to " + EXTENSION_POINT_ID + ". Must implements org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler"; JavaLanguageServerPlugin.logError(message); return null; } } catch (CoreException e) { JavaLanguageServerPlugin.logException("Unable to create delegate command handler ", e); return null; } } return fDelegateCommandHandlerInstance; } }
@Override public void exit() { logInfo(">> exit"); JavaLanguageServerPlugin.getLanguageServer().exit(); Executors.newSingleThreadScheduledExecutor().schedule(() -> { logInfo("Forcing exit after 1 min."); System.exit(FORCED_EXIT_CODE); }, 1, TimeUnit.MINUTES); }
@Override public Object start(IApplicationContext context) throws Exception { JavaLanguageServerPlugin.startLanguageServer(this); synchronized(waitLock){ while (!shutdown) { try { context.applicationRunning(); JavaLanguageServerPlugin.logInfo("Main thread is waiting"); waitLock.wait(); } catch (InterruptedException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } } } return IApplication.EXIT_OK; }
@Override public void handleException(Throwable exception) { JavaLanguageServerPlugin.logException("Exception happened inside DynamicValidationStateChange: ", exception); } });
public List<FileSystemWatcher> registerWatchers() { logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'"); if (preferenceManager.getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) { Set<String> sources = new HashSet<>(); JavaLanguageServerPlugin.logException(e.getMessage(), e); 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(sources);
@Override public String getSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException { String source = null; try { IBuffer buffer = classFile.getBuffer(); if (buffer != null) { if (monitor.isCanceled()) { return null; } source = buffer.getContents(); JavaLanguageServerPlugin.logInfo("ClassFile contents request completed"); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Exception getting java element ", e); } return source; }
static ImportRewrite createImportRewrite(ICompilationUnit compilationUnit) { try { ImportRewrite rewrite = ImportRewrite.create(compilationUnit, true); String[] importOrder = JavaLanguageServerPlugin.getPreferencesManager() == null ? new String[0] : JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getImportOrder(); rewrite.setImportOrder(importOrder); rewrite.setOnDemandImportThreshold(IMPORTS_THRESHOLD); rewrite.setStaticOnDemandImportThreshold(IMPORTS_THRESHOLD); return rewrite; } catch (JavaModelException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); return null; } }
@SuppressWarnings("unchecked") InitializeResult initialize(InitializeParams param) { logInfo("Initializing Java Language Server " + JavaLanguageServerPlugin.getVersion()); Map<?, ?> initializationOptions = this.getInitializationOptions(param); Map<String, Object> extendedClientCapabilities = getInitializationOption(initializationOptions, "extendedClientCapabilities", Map.class); rootPath = param.getRootPath(); if (rootPath != null) { logInfo("In LSP 3.0, InitializeParams.rootPath is deprecated in favour of InitializeParams.rootUri!"); logInfo("No workspace folders or root uri was defined. Falling back on " + workspaceLocation); rootPaths.add(workspaceLocation); Integer processId = param.getProcessId(); if (processId != null) { JavaLanguageServerPlugin.getLanguageServer().setParentProcessId(processId.longValue()); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Failed to load extension bundles ", e);
project.delete(false, true, subMonitor.split(1)); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Problems removing '" + project.getName() + "' from workspace.", e); long elapsed = System.currentTimeMillis() - start; JavaLanguageServerPlugin.logInfo("Updated workspace folders in " + elapsed + " ms: Added " + addedRootPaths.size() + " folder(s), removed" + removedRootPaths.size() + " folders."); JavaLanguageServerPlugin.logInfo(getWorkspaceInfo()); return Status.OK_STATUS; } catch (CoreException e) { String msg = "Error updating workspace folders"; JavaLanguageServerPlugin.logError(msg); status = StatusFactory.newErrorStatus(msg, e);
final OrganizeImportsCommand c = new OrganizeImportsCommand(); final Object result = c.organizeImports(arguments); final boolean applyNow = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isWorkspaceApplyEditSupported(); if (applyNow) { JavaLanguageServerPlugin.getInstance().getClientConnection().applyWorkspaceEdit((WorkspaceEdit) result);
public static void configureFormatter(PreferenceManager preferenceManager, ProjectsManager projectsManager) { String formatterUrl = preferenceManager.getPreferences().getFormatterUrl(); Map<String, String> options = null; if (formatterUrl != null) { URL url = projectsManager.getUrl(formatterUrl); if (url != null) { try (InputStream inputStream = url.openStream()) { InputSource inputSource = new InputSource(inputStream); String profileName = preferenceManager.getPreferences().getFormatterProfileName(); options = FormatterManager.readSettingsFromStream(inputSource, profileName); } catch (Exception e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } } else { JavaLanguageServerPlugin.logInfo("Invalid formatter:" + formatterUrl); } } if (options != null && !options.isEmpty()) { setFormattingOptions(options); } else { Map<String, String> defaultOptions = DefaultCodeFormatterOptions.getEclipseDefaultSettings().getMap(); Hashtable<String, String> javaOptions = JavaCore.getOptions(); defaultOptions.forEach((k, v) -> { javaOptions.put(k, v); }); JavaCore.setOptions(javaOptions); JavaLanguageServerPlugin.getPreferencesManager().initialize(); } }
BundleContext context = JavaLanguageServerPlugin.getBundleContext(); MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Load bundle list", null); Collection<Bundle> bundlesToStart = new ArrayList<>(); try { if (StringUtils.isEmpty(bundleLocation)) { JavaLanguageServerPlugin.logError("Empty bundle location"); continue; JavaLanguageServerPlugin.logInfo("Installed " + bundle.getLocation()); bundlesToStart.add(bundle);
IProject project = JavaLanguageServerPlugin.getProjectsManager().getDefaultProject(); if (project == null || !project.isAccessible()) { return null; } catch (CoreException e) { String errMsg = "Failed to create linked resource from " + uri + " to " + project.getName(); JavaLanguageServerPlugin.logException(errMsg, e);
ContentProviderManager contentProvider = JavaLanguageServerPlugin.getContentProviderManager(); String contents = contentProvider.getSource(classFile, monitor); if (contents != null) { JavaLanguageServerPlugin.logException(e.getMessage(), e);
@Override public CompletableFuture<String> classFileContents(TextDocumentIdentifier param) { logInfo(">> java/classFileContents"); ContentProviderManager handler = JavaLanguageServerPlugin.getContentProviderManager(); URI uri = JDTUtils.toURI(param.getUri()); return computeAsync((monitor) -> handler.getContent(uri, monitor)); }
public MavenProjectImporter() { this.configurationManager = MavenPlugin.getProjectConfigurationManager(); this.digestStore = JavaLanguageServerPlugin.getDigestStore(); }
@Override public InputStream getInputStream() throws IOException { return JavaLanguageServerPlugin.getIn(); }