Skip to content

Commit 2c6e8d6

Browse files
committed
Fixes to TelemetryServerManager to ensure multi-module projects under a
workspace root are recognized 1. Amended LspServerTelemetryManager.sendWorkspaceInfo to use a NavigableMap to find sub-paths of the workspaceFolder that correspond to Projects, when it is not itself a Project. 2. Also, caught exceptions from ProjectProblems.isBroken() since it maybe a sign of a broken project. Signed-off-by: Siddharth Srinivasan <[email protected]>
1 parent 6d248c4 commit 2c6e8d6

File tree

1 file changed

+78
-39
lines changed

1 file changed

+78
-39
lines changed

patches/nb-telemetry.diff

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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
33
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java
44
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspServerTelemetryManager.java
55
@@ -21,6 +21,7 @@ package org.netbeans.modules.java.lsp.server.protocol;
@@ -10,7 +10,7 @@ index d82646afb1..3d507b5fe3 100644
1010
import java.math.BigInteger;
1111
import java.nio.charset.StandardCharsets;
1212
import java.security.MessageDigest;
13-
@@ -28,25 +29,27 @@ import java.security.NoSuchAlgorithmException;
13+
@@ -28,25 +29,29 @@ import java.security.NoSuchAlgorithmException;
1414
import java.util.ArrayList;
1515
import java.util.Collection;
1616
import java.util.Collections;
@@ -19,6 +19,8 @@ index d82646afb1..3d507b5fe3 100644
1919
import java.util.List;
2020
import java.util.Map;
2121
-import java.util.Set;
22+
+import java.util.NavigableMap;
23+
+import java.util.TreeMap;
2224
import java.util.WeakHashMap;
2325
import java.util.concurrent.Future;
2426
-import java.util.concurrent.atomic.AtomicBoolean;
@@ -42,7 +44,7 @@ index d82646afb1..3d507b5fe3 100644
4244
import org.openide.util.Lookup;
4345

4446
/**
45-
@@ -55,130 +58,171 @@ import org.openide.util.Lookup;
47+
@@ -55,130 +60,200 @@ import org.openide.util.Lookup;
4648
*/
4749
public class LspServerTelemetryManager {
4850

@@ -83,11 +85,11 @@ index d82646afb1..3d507b5fe3 100644
8385
+
8486
+ private static final LspServerTelemetryManager instance = new LspServerTelemetryManager();
8587
+ }
86-
88+
+
8789
+ private final WeakHashMap<LanguageClient, WeakReference<Future<Void>>> clients = new WeakHashMap<>();
8890
+ private volatile boolean telemetryEnabled = false;
8991
+ private long lspServerIntializationTime;
90-
+
92+
9193
+ public boolean isTelemetryEnabled() {
9294
+ return telemetryEnabled;
9395
+ }
@@ -175,22 +177,21 @@ index d82646afb1..3d507b5fe3 100644
175177
JsonArray prjProps = new JsonArray();
176178

177179
- 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));
180183

181184
for (FileObject workspaceFolder : workspaceClientFolders) {
182185
try {
183-
JsonObject obj = new JsonObject();
186+
- JsonObject obj = new JsonObject();
187+
+ boolean noProjectFound = true;
184188
String prjPath = workspaceFolder.getPath();
185189
- String prjId = this.getPrjId(prjPath);
186-
+ String prjId = getPrjId(prjPath);
187-
obj.addProperty("id", prjId);
190+
- obj.addProperty("id", prjId);
188191
-
189192
- // In future if different JDK is used for different project then this can be updated
190193
- obj.addProperty("javaVersion", System.getProperty("java.version"));
191-
+ String javaVersion = getProjectJavaVersion();
192-
+ obj.addProperty("javaVersion", javaVersion);
193-
194+
-
194195
- if (mp.containsKey(prjPath)) {
195196
- Project prj = mp.get(prjPath);
196197
-
@@ -202,31 +203,40 @@ index d82646afb1..3d507b5fe3 100644
202203
-
203204
- boolean isPreviewFlagEnabled = this.isEnablePreivew(prj.getProjectDirectory(), projectType);
204205
- 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 {
212207
- obj.addProperty("buildTool", this.STANDALONE_PRJ);
213208
- obj.addProperty("javaVersion", System.getProperty("java.version"));
214209
- obj.addProperty("openedWithProblems", false);
215210
-
216211
- boolean isPreviewFlagEnabled = this.isEnablePreivew(workspaceFolder, this.STANDALONE_PRJ);
217212
- 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;
221230
}
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+
-
228234
- } catch (NoSuchAlgorithmException ex) {
229235
- Exceptions.printStackTrace(ex);
236+
+ if (noProjectFound) {
237+
+ // No project found
238+
+ prjProps.add(createProjectInfo(prjPath, null, workspaceFolder, client));
239+
+ }
230240
+ } catch (NoSuchAlgorithmException e) {
231241
+ LOG.log(Level.INFO, "NoSuchAlgorithmException while creating workspaceInfo event: {0}", e.getMessage());
232242
+ } catch (Exception e) {
@@ -236,26 +246,55 @@ index d82646afb1..3d507b5fe3 100644
236246

237247
- properties.add("prjsInfo", prjProps);
238248
+ properties.add("projectInfo", prjProps);
239-
+
240-
+ properties.addProperty("projInitTimeTaken", timeToOpenProjects);
241-
+ properties.addProperty("numProjects", workspaceClientFolders.size());
242-
+ properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
243249

244250
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
245251
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
246252
- 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+
250257
- 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));
253259
}
254260
-
255261
- private boolean isEnablePreivew(FileObject source, String prjType) {
256262
- if (prjType.equals(this.STANDALONE_PRJ)) {
257263
- NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
258264
+
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+
+
259298
+ public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
260299
+ if (prjType == ProjectType.standalone) {
261300
+ NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null ;
@@ -292,7 +331,7 @@ index d82646afb1..3d507b5fe3 100644
292331
}
293332

294333
private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
295-
@@ -187,15 +231,50 @@ public class LspServerTelemetryManager {
334+
@@ -187,15 +262,50 @@ public class LspServerTelemetryManager {
296335

297336
BigInteger number = new BigInteger(1, hash);
298337

0 commit comments

Comments
 (0)