1
1
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java
2
- index d82646afb1..b008279cc4 100644
2
+ index d82646afb1..7f4c88acd1 100644
3
3
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java
4
4
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java
5
5
@@ -21,6 +21,7 @@ package org.netbeans.modules.java.lsp.server.protocol;
@@ -10,7 +10,7 @@ index d82646afb1..b008279cc4 100644
10
10
import java.math.BigInteger;
11
11
import java.nio.charset.StandardCharsets;
12
12
import java.security.MessageDigest;
13
- @@ -28,25 +29,29 @@ import java.security.NoSuchAlgorithmException;
13
+ @@ -28,25 +29,30 @@ import java.security.NoSuchAlgorithmException;
14
14
import java.util.ArrayList;
15
15
import java.util.Collection;
16
16
import java.util.Collections;
@@ -22,6 +22,7 @@ index d82646afb1..b008279cc4 100644
22
22
+ import java.util.NavigableMap;
23
23
+ import java.util.TreeMap;
24
24
import java.util.WeakHashMap;
25
+ + import java.util.concurrent.CompletableFuture;
25
26
import java.util.concurrent.Future;
26
27
- import java.util.concurrent.atomic.AtomicBoolean;
27
28
+ import java.util.function.Function;
@@ -44,7 +45,7 @@ index d82646afb1..b008279cc4 100644
44
45
import org.openide.util.Lookup;
45
46
46
47
/**
47
- @@ -55,130 +60,200 @@ import org.openide.util.Lookup;
48
+ @@ -55,130 +61,205 @@ import org.openide.util.Lookup;
48
49
*/
49
50
public class LspServerTelemetryManager {
50
51
@@ -85,11 +86,11 @@ index d82646afb1..b008279cc4 100644
85
86
+
86
87
+ private static final LspServerTelemetryManager instance = new LspServerTelemetryManager();
87
88
+ }
88
- +
89
+
89
90
+ private final WeakHashMap<LanguageClient, WeakReference<Future<Void>>> clients = new WeakHashMap<>();
90
91
+ private volatile boolean telemetryEnabled = false;
91
92
+ private long lspServerIntializationTime;
92
-
93
+ +
93
94
+ public boolean isTelemetryEnabled() {
94
95
+ return telemetryEnabled;
95
96
+ }
@@ -172,9 +173,10 @@ index d82646afb1..b008279cc4 100644
172
173
+ return close == null || close.isDone();
173
174
+ }
174
175
+
175
- + public void sendWorkspaceInfo(LanguageClient client, List<FileObject> workspaceClientFolders, Collection<Project> projects, long timeToOpenProjects) {
176
+ + public CompletableFuture<Void> sendWorkspaceInfo(LanguageClient client, List<FileObject> workspaceClientFolders, Collection<Project> projects, long timeToOpenProjects) {
176
177
JsonObject properties = new JsonObject();
177
- JsonArray prjProps = new JsonArray();
178
+ - JsonArray prjProps = new JsonArray();
179
+ + List<CompletableFuture<JsonObject>> createProjectFutures = new ArrayList<>();
178
180
179
181
- Map<String, Project> mp = prjs.stream()
180
182
- .collect(Collectors.toMap(project -> project.getProjectDirectory().getPath(), project -> project));
@@ -215,14 +217,14 @@ index d82646afb1..b008279cc4 100644
215
217
+ String projectPath = p.getKey();
216
218
+ if (prjPathWithSlash == null) {
217
219
+ if (prjPath.equals(projectPath)) {
218
- + prjProps .add(createProjectInfo(prjPath, p.getValue(), workspaceFolder, client));
220
+ + createProjectFutures .add(createProjectInfo(prjPath, p.getValue(), workspaceFolder, client));
219
221
+ noProjectFound = false;
220
222
+ break;
221
223
+ }
222
224
+ prjPathWithSlash = prjPath + '/';
223
225
+ }
224
226
+ if (projectPath.startsWith(prjPathWithSlash)) {
225
- + prjProps .add(createProjectInfo(p.getKey(), p.getValue(), workspaceFolder, client));
227
+ + createProjectFutures .add(createProjectInfo(p.getKey(), p.getValue(), workspaceFolder, client));
226
228
+ noProjectFound = false;
227
229
+ continue;
228
230
+ }
@@ -235,7 +237,7 @@ index d82646afb1..b008279cc4 100644
235
237
- Exceptions.printStackTrace(ex);
236
238
+ if (noProjectFound) {
237
239
+ // No project found
238
- + prjProps .add(createProjectInfo(prjPath, null, workspaceFolder, client));
240
+ + createProjectFutures .add(createProjectInfo(prjPath, null, workspaceFolder, client));
239
241
+ }
240
242
+ } catch (NoSuchAlgorithmException e) {
241
243
+ LOG.log(Level.INFO, "NoSuchAlgorithmException while creating workspaceInfo event: {0}", e.getMessage());
@@ -245,24 +247,25 @@ index d82646afb1..b008279cc4 100644
245
247
}
246
248
247
249
- properties.add("prjsInfo", prjProps);
248
- + properties.add("projectInfo", prjProps);
250
+ + return CompletableFuture.allOf(createProjectFutures.toArray(new CompletableFuture[0]))
251
+ + .thenApply((ignored) -> {
252
+ + JsonArray prjProps = new JsonArray();
253
+ + createProjectFutures.forEach((f) -> prjProps.add(f.join()));
254
+ + return prjProps;
255
+ + })
256
+ + .thenAccept((prjProps) -> {
257
+ + properties.add("projectInfo", prjProps);
258
+ + properties.addProperty("projInitTimeTaken", timeToOpenProjects);
259
+ + properties.addProperty("numProjects", workspaceClientFolders.size());
260
+ + properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
261
+ + this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
262
+ + });
263
+ + }
249
264
250
265
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
251
266
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
252
267
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
253
- + properties.addProperty("projInitTimeTaken", timeToOpenProjects);
254
- + properties.addProperty("numProjects", workspaceClientFolders.size());
255
- + properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
256
-
257
- - this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
258
- + this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
259
- }
260
- -
261
- - private boolean isEnablePreivew(FileObject source, String prjType) {
262
- - if (prjType.equals(this.STANDALONE_PRJ)) {
263
- - NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
264
- +
265
- + private JsonObject createProjectInfo(String prjPath, Project prj, FileObject workspaceFolder, LanguageClient client) throws NoSuchAlgorithmException {
268
+ + private CompletableFuture<JsonObject> createProjectInfo(String prjPath, Project prj, FileObject workspaceFolder, LanguageClient client) throws NoSuchAlgorithmException {
266
269
+ JsonObject obj = new JsonObject();
267
270
+ String prjId = getPrjId(prjPath);
268
271
+ obj.addProperty("id", prjId);
@@ -286,27 +289,32 @@ index d82646afb1..b008279cc4 100644
286
289
+ String javaVersion = getProjectJavaVersion();
287
290
+ obj.addProperty("javaVersion", javaVersion);
288
291
+ obj.addProperty("buildTool", projectType.name());
289
- + boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client);
290
- + obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
291
- + return obj;
292
+ + return isPreviewEnabled(projectDirectory, projectType, client).thenApply(isPreviewFlagEnabled -> {
293
+ + obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
294
+ + return obj;
295
+ + });
292
296
+ }
293
- +
294
- + public boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
297
+
298
+ - this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
299
+ + public CompletableFuture<Boolean> isPreviewEnabled(FileObject source, ProjectType prjType) {
295
300
+ return isPreviewEnabled(source, prjType, null);
296
- + }
301
+ }
302
+ -
303
+ - private boolean isEnablePreivew(FileObject source, String prjType) {
304
+ - if (prjType.equals(this.STANDALONE_PRJ)) {
305
+ - NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
297
306
+
298
- + public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
307
+ + public CompletableFuture<Boolean> isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
299
308
+ if (prjType == ProjectType.standalone) {
300
- + NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null ;
309
+ + NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null;
301
310
if (client == null) {
302
311
- return false;
303
312
+ client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
304
313
+ if (client == null) {
305
- + return false;
314
+ + return CompletableFuture.completedFuture( false) ;
306
315
+ }
307
316
}
308
317
- AtomicBoolean isEnablePreviewSet = new AtomicBoolean(false);
309
- + boolean[] isEnablePreviewSet = {false};
310
318
ConfigurationItem conf = new ConfigurationItem();
311
319
- conf.setSection(client.getNbCodeCapabilities().getAltConfigurationPrefix() + "runConfig.vmOptions");
312
320
- client.configuration(new ConfigurationParams(Collections.singletonList(conf))).thenAccept(c -> {
@@ -316,22 +324,21 @@ index d82646afb1..b008279cc4 100644
316
324
-
317
325
- return isEnablePreviewSet.get();
318
326
+ conf.setSection(client.getNbCodeCapabilities().getConfigurationPrefix() + "runConfig.vmOptions");
319
- + client.configuration(new ConfigurationParams(Collections.singletonList(conf)))
320
- + .thenAccept (c -> {
321
- + isEnablePreviewSet[0] = c != null && !c.isEmpty()
327
+ + return client.configuration(new ConfigurationParams(Collections.singletonList(conf)))
328
+ + .thenApply (c -> {
329
+ + return c != null && !c.isEmpty()
322
330
+ && ((JsonPrimitive) c.get(0)).getAsString().contains(ENABLE_PREVIEW);
323
331
+ });
324
- + return isEnablePreviewSet[0];
325
332
}
326
333
-
327
334
+
328
335
Result result = CompilerOptionsQuery.getOptions(source);
329
336
- return result.getArguments().contains(this.ENABLE_PREVIEW);
330
- + return result.getArguments().contains(ENABLE_PREVIEW);
337
+ + return CompletableFuture.completedFuture( result.getArguments().contains(ENABLE_PREVIEW) );
331
338
}
332
339
333
340
private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
334
- @@ -187,15 +262 ,50 @@ public class LspServerTelemetryManager {
341
+ @@ -187,15 +268 ,50 @@ public class LspServerTelemetryManager {
335
342
336
343
BigInteger number = new BigInteger(1, hash);
337
344
0 commit comments