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..3d507b5fe3 100644
2
+ index d82646afb1..b008279cc4 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..3d507b5fe3 100644
10
10
import java.math.BigInteger;
11
11
import java.nio.charset.StandardCharsets;
12
12
import java.security.MessageDigest;
13
- @@ -28,25 +29,27 @@ import java.security.NoSuchAlgorithmException;
13
+ @@ -28,25 +29,29 @@ import java.security.NoSuchAlgorithmException;
14
14
import java.util.ArrayList;
15
15
import java.util.Collection;
16
16
import java.util.Collections;
@@ -19,6 +19,8 @@ index d82646afb1..3d507b5fe3 100644
19
19
import java.util.List;
20
20
import java.util.Map;
21
21
- import java.util.Set;
22
+ + import java.util.NavigableMap;
23
+ + import java.util.TreeMap;
22
24
import java.util.WeakHashMap;
23
25
import java.util.concurrent.Future;
24
26
- import java.util.concurrent.atomic.AtomicBoolean;
@@ -42,7 +44,7 @@ index d82646afb1..3d507b5fe3 100644
42
44
import org.openide.util.Lookup;
43
45
44
46
/**
45
- @@ -55,130 +58,171 @@ import org.openide.util.Lookup;
47
+ @@ -55,130 +60,200 @@ import org.openide.util.Lookup;
46
48
*/
47
49
public class LspServerTelemetryManager {
48
50
@@ -83,11 +85,11 @@ index d82646afb1..3d507b5fe3 100644
83
85
+
84
86
+ private static final LspServerTelemetryManager instance = new LspServerTelemetryManager();
85
87
+ }
86
-
88
+ +
87
89
+ private final WeakHashMap<LanguageClient, WeakReference<Future<Void>>> clients = new WeakHashMap<>();
88
90
+ private volatile boolean telemetryEnabled = false;
89
91
+ private long lspServerIntializationTime;
90
- +
92
+
91
93
+ public boolean isTelemetryEnabled() {
92
94
+ return telemetryEnabled;
93
95
+ }
@@ -175,22 +177,21 @@ index d82646afb1..3d507b5fe3 100644
175
177
JsonArray prjProps = new JsonArray();
176
178
177
179
- Map<String, Project> mp = prjs.stream()
178
- + Map<String, Project> mp = projects.stream()
179
- .collect(Collectors.toMap(project -> project.getProjectDirectory().getPath(), project -> project));
180
+ - .collect(Collectors.toMap(project -> project.getProjectDirectory().getPath(), project -> project));
181
+ + NavigableMap<String, Project> mp = projects.stream()
182
+ + .collect(Collectors.toMap(project -> project.getProjectDirectory().getPath(), project -> project, (p1, p2) -> p1, TreeMap<String, Project>::new));
180
183
181
184
for (FileObject workspaceFolder : workspaceClientFolders) {
182
185
try {
183
- JsonObject obj = new JsonObject();
186
+ - JsonObject obj = new JsonObject();
187
+ + boolean noProjectFound = true;
184
188
String prjPath = workspaceFolder.getPath();
185
189
- String prjId = this.getPrjId(prjPath);
186
- + String prjId = getPrjId(prjPath);
187
- obj.addProperty("id", prjId);
190
+ - obj.addProperty("id", prjId);
188
191
-
189
192
- // In future if different JDK is used for different project then this can be updated
190
193
- obj.addProperty("javaVersion", System.getProperty("java.version"));
191
- + String javaVersion = getProjectJavaVersion();
192
- + obj.addProperty("javaVersion", javaVersion);
193
-
194
+ -
194
195
- if (mp.containsKey(prjPath)) {
195
196
- Project prj = mp.get(prjPath);
196
197
-
@@ -202,31 +203,40 @@ index d82646afb1..3d507b5fe3 100644
202
203
-
203
204
- boolean isPreviewFlagEnabled = this.isEnablePreivew(prj.getProjectDirectory(), projectType);
204
205
- obj.addProperty("enablePreview", isPreviewFlagEnabled);
205
- + Project prj = mp.get(prjPath);
206
- + FileObject projectDirectory;
207
- + ProjectType projectType;
208
- + if (prj == null) {
209
- + projectType = ProjectType.standalone;
210
- + projectDirectory = workspaceFolder;
211
- } else {
206
+ - } else {
212
207
- obj.addProperty("buildTool", this.STANDALONE_PRJ);
213
208
- obj.addProperty("javaVersion", System.getProperty("java.version"));
214
209
- obj.addProperty("openedWithProblems", false);
215
210
-
216
211
- boolean isPreviewFlagEnabled = this.isEnablePreivew(workspaceFolder, this.STANDALONE_PRJ);
217
212
- obj.addProperty("enablePreview", isPreviewFlagEnabled);
218
- + projectType = getProjectType(prj);
219
- + projectDirectory = prj.getProjectDirectory();
220
- + obj.addProperty("isOpenedWithProblems", ProjectProblems.isBroken(prj));
213
+ + String prjPathWithSlash = null;
214
+ + for (Map.Entry<String, Project> p : mp.tailMap(prjPath, true).entrySet()) {
215
+ + String projectPath = p.getKey();
216
+ + if (prjPathWithSlash == null) {
217
+ + if (prjPath.equals(projectPath)) {
218
+ + prjProps.add(createProjectInfo(prjPath, p.getValue(), workspaceFolder, client));
219
+ + noProjectFound = false;
220
+ + break;
221
+ + }
222
+ + prjPathWithSlash = prjPath + '/';
223
+ + }
224
+ + if (projectPath.startsWith(prjPathWithSlash)) {
225
+ + prjProps.add(createProjectInfo(p.getKey(), p.getValue(), workspaceFolder, client));
226
+ + noProjectFound = false;
227
+ + continue;
228
+ + }
229
+ + break;
221
230
}
222
- + obj.addProperty("buildTool", projectType.name());
223
- + boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client);
224
- + obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
225
-
226
- prjProps.add(obj);
227
-
231
+ -
232
+ - prjProps.add(obj);
233
+ -
228
234
- } catch (NoSuchAlgorithmException ex) {
229
235
- Exceptions.printStackTrace(ex);
236
+ + if (noProjectFound) {
237
+ + // No project found
238
+ + prjProps.add(createProjectInfo(prjPath, null, workspaceFolder, client));
239
+ + }
230
240
+ } catch (NoSuchAlgorithmException e) {
231
241
+ LOG.log(Level.INFO, "NoSuchAlgorithmException while creating workspaceInfo event: {0}", e.getMessage());
232
242
+ } catch (Exception e) {
@@ -236,26 +246,55 @@ index d82646afb1..3d507b5fe3 100644
236
246
237
247
- properties.add("prjsInfo", prjProps);
238
248
+ properties.add("projectInfo", prjProps);
239
- +
240
- + properties.addProperty("projInitTimeTaken", timeToOpenProjects);
241
- + properties.addProperty("numProjects", workspaceClientFolders.size());
242
- + properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
243
249
244
250
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
245
251
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
246
252
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
247
- + this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
248
- + }
249
-
253
+ + properties.addProperty("projInitTimeTaken", timeToOpenProjects);
254
+ + properties.addProperty("numProjects", workspaceClientFolders.size());
255
+ + properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
256
+
250
257
- this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
251
- + public boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
252
- + return isPreviewEnabled(source, prjType, null);
258
+ + this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
253
259
}
254
260
-
255
261
- private boolean isEnablePreivew(FileObject source, String prjType) {
256
262
- if (prjType.equals(this.STANDALONE_PRJ)) {
257
263
- NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
258
264
+
265
+ + private JsonObject createProjectInfo(String prjPath, Project prj, FileObject workspaceFolder, LanguageClient client) throws NoSuchAlgorithmException {
266
+ + JsonObject obj = new JsonObject();
267
+ + String prjId = getPrjId(prjPath);
268
+ + obj.addProperty("id", prjId);
269
+ + FileObject projectDirectory;
270
+ + ProjectType projectType;
271
+ + if (prj == null) {
272
+ + projectType = ProjectType.standalone;
273
+ + projectDirectory = workspaceFolder;
274
+ + } else {
275
+ + projectType = getProjectType(prj);
276
+ + projectDirectory = prj.getProjectDirectory();
277
+ + boolean projectHasProblems;
278
+ + try {
279
+ + projectHasProblems = ProjectProblems.isBroken(prj);
280
+ + } catch (RuntimeException e) {
281
+ + LOG.log(Level.INFO, "Exception while checking project problems for workspaceInfo event: {0}", e.getMessage());
282
+ + projectHasProblems = true;
283
+ + }
284
+ + obj.addProperty("isOpenedWithProblems", projectHasProblems);
285
+ + }
286
+ + String javaVersion = getProjectJavaVersion();
287
+ + obj.addProperty("javaVersion", javaVersion);
288
+ + obj.addProperty("buildTool", projectType.name());
289
+ + boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client);
290
+ + obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
291
+ + return obj;
292
+ + }
293
+ +
294
+ + public boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
295
+ + return isPreviewEnabled(source, prjType, null);
296
+ + }
297
+ +
259
298
+ public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
260
299
+ if (prjType == ProjectType.standalone) {
261
300
+ NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null ;
@@ -292,7 +331,7 @@ index d82646afb1..3d507b5fe3 100644
292
331
}
293
332
294
333
private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
295
- @@ -187,15 +231 ,50 @@ public class LspServerTelemetryManager {
334
+ @@ -187,15 +262 ,50 @@ public class LspServerTelemetryManager {
296
335
297
336
BigInteger number = new BigInteger(1, hash);
298
337
0 commit comments