Skip to content

Commit 6d248c4

Browse files
authored
Merge pull request #360 from sid-srini/telemetry-handle-jdkFeature-event
Fixes and edits to telemetry code to support JdkFeatureEvent
2 parents b2dca8e + 2d51716 commit 6d248c4

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

patches/nb-telemetry.diff

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ index d82646afb1..3d507b5fe3 100644
4242
import org.openide.util.Lookup;
4343

4444
/**
45-
@@ -55,130 +58,164 @@ import org.openide.util.Lookup;
45+
@@ -55,130 +58,171 @@ import org.openide.util.Lookup;
4646
*/
4747
public class LspServerTelemetryManager {
4848

@@ -63,7 +63,7 @@ index d82646afb1..3d507b5fe3 100644
6363
- public synchronized void connect(LanguageClient client, Future<Void> future) {
6464
- clients.put(client, future);
6565
- lspServerIntiailizationTime = System.currentTimeMillis();
66-
+ private static enum ProjectType {
66+
+ public static enum ProjectType {
6767
+ standalone,
6868
+ maven,
6969
+ gradle;
@@ -188,12 +188,12 @@ index d82646afb1..3d507b5fe3 100644
188188
-
189189
- // In future if different JDK is used for different project then this can be updated
190190
- obj.addProperty("javaVersion", System.getProperty("java.version"));
191-
-
192-
- if (mp.containsKey(prjPath)) {
193-
- Project prj = mp.get(prjPath);
194191
+ String javaVersion = getProjectJavaVersion();
195192
+ obj.addProperty("javaVersion", javaVersion);
196-
193+
194+
- if (mp.containsKey(prjPath)) {
195+
- Project prj = mp.get(prjPath);
196+
-
197197
- ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
198198
- String projectType = r.getProjectType();
199199
- obj.addProperty("buildTool", (projectType.contains("maven") ? "MavenProject" : "GradleProject"));
@@ -220,7 +220,7 @@ index d82646afb1..3d507b5fe3 100644
220220
+ obj.addProperty("isOpenedWithProblems", ProjectProblems.isBroken(prj));
221221
}
222222
+ obj.addProperty("buildTool", projectType.name());
223-
+ boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType);
223+
+ boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client);
224224
+ obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
225225

226226
prjProps.add(obj);
@@ -236,26 +236,35 @@ index d82646afb1..3d507b5fe3 100644
236236

237237
- properties.add("prjsInfo", prjProps);
238238
+ properties.add("projectInfo", prjProps);
239-
240-
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
241-
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
242-
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
239+
+
243240
+ properties.addProperty("projInitTimeTaken", timeToOpenProjects);
244241
+ properties.addProperty("numProjects", workspaceClientFolders.size());
245242
+ properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
246243

247-
- this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
244+
- properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
245+
- properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
246+
- properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
248247
+ this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
248+
+ }
249+
250+
- 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);
249253
}
250254
-
251255
- private boolean isEnablePreivew(FileObject source, String prjType) {
252256
- if (prjType.equals(this.STANDALONE_PRJ)) {
257+
- NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
253258
+
254-
+ private boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
259+
+ public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient) {
255260
+ if (prjType == ProjectType.standalone) {
256-
NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
261+
+ NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? (NbCodeLanguageClient) languageClient : null ;
257262
if (client == null) {
258-
return false;
263+
- return false;
264+
+ client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
265+
+ if (client == null) {
266+
+ return false;
267+
+ }
259268
}
260269
- AtomicBoolean isEnablePreviewSet = new AtomicBoolean(false);
261270
+ boolean[] isEnablePreviewSet = {false};
@@ -283,7 +292,7 @@ index d82646afb1..3d507b5fe3 100644
283292
}
284293

285294
private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
286-
@@ -187,15 +224,50 @@ public class LspServerTelemetryManager {
295+
@@ -187,15 +231,50 @@ public class LspServerTelemetryManager {
287296

288297
BigInteger number = new BigInteger(1, hash);
289298

@@ -331,7 +340,7 @@ index d82646afb1..3d507b5fe3 100644
331340
+ return propertyLookup.apply("java.vm.name");
332341
+ }
333342
+
334-
+ private ProjectType getProjectType(Project prj) {
343+
+ public ProjectType getProjectType(Project prj) {
335344
+ ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
336345
+ String projectType = r == null ? null : r.getProjectType();
337346
+ return projectType != null && projectType.contains(ProjectType.maven.name()) ? ProjectType.maven : ProjectType.gradle;
@@ -358,7 +367,7 @@ index 9134992f5f..f070fec320 100644
358367
}
359368

360369
+ public boolean wantsTelemetryEnabled() {
361-
+ return wantsTelemetryEnabled;
370+
+ return wantsTelemetryEnabled == Boolean.TRUE;
362371
+ }
363372
+
364373
private NbCodeClientCapabilities withCapabilities(ClientCapabilities caps) {

vscode/src/lsp/listeners/notifications/handlers.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { LOGGER } from '../../../logger';
2525
import { globalState } from "../../../globalState";
2626
import { WorkspaceChangeData, WorkspaceChangeEvent } from "../../../telemetry/events/workspaceChange";
2727
import { Telemetry } from "../../../telemetry/telemetry";
28+
import { JdkFeatureEvent, JdkFeatureEventData } from "../../../telemetry/events/jdkFeature";
2829

2930
const checkInstallNbJavac = (msg: string) => {
3031
const NO_JAVA_SUPPORT = "Cannot initialize Java support";
@@ -44,8 +45,8 @@ const checkInstallNbJavac = (msg: string) => {
4445
}
4546
}
4647

47-
const showStatusBarMessageHandler = (params : ShowStatusMessageParams) => {
48-
let decorated : string = params.message;
48+
const showStatusBarMessageHandler = (params: ShowStatusMessageParams) => {
49+
let decorated: string = params.message;
4950
let defTimeout;
5051

5152
switch (params.type) {
@@ -100,7 +101,7 @@ const textEditorDecorationDisposeHandler = (param: any) => {
100101
if (decorationType) {
101102
globalState.removeDecoration(param);
102103
decorationType.dispose();
103-
104+
104105
globalState.getDecorationParamsByUri().forEach((value, key) => {
105106
if (value.key == param) {
106107
globalState.removeDecorationParams(key);
@@ -111,8 +112,8 @@ const textEditorDecorationDisposeHandler = (param: any) => {
111112

112113

113114
const telemetryEventHandler = (param: any) => {
114-
if(WorkspaceChangeEvent.NAME === param?.name){
115-
const {projectInfo, numProjects, lspInitTimeTaken, projInitTimeTaken} = param?.properties;
115+
if (WorkspaceChangeEvent.NAME === param?.name) {
116+
const { projectInfo, numProjects, lspInitTimeTaken, projInitTimeTaken } = param?.properties;
116117
const eventData: WorkspaceChangeData = {
117118
projectInfo,
118119
numProjects,
@@ -123,6 +124,18 @@ const telemetryEventHandler = (param: any) => {
123124
Telemetry.sendTelemetry(workspaceChangeEvent);
124125
return;
125126
}
127+
if (JdkFeatureEvent.NAME === param?.name) {
128+
const { javaVersion, names, jeps, isPreviewEnabled } = param?.properties;
129+
const eventData: JdkFeatureEventData = {
130+
jeps,
131+
names,
132+
javaVersion,
133+
isPreviewEnabled
134+
};
135+
const jdkFeatureEvent: JdkFeatureEvent = new JdkFeatureEvent(eventData);
136+
Telemetry.sendTelemetry(jdkFeatureEvent);
137+
return;
138+
}
126139
const ls = globalState.getListener(param);
127140
if (ls) {
128141
for (const listener of ls) {
@@ -131,7 +144,7 @@ const telemetryEventHandler = (param: any) => {
131144
}
132145
}
133146

134-
export const notificationListeners : notificationOrRequestListenerType[] = [{
147+
export const notificationListeners: notificationOrRequestListenerType[] = [{
135148
type: StatusMessageRequest.type,
136149
handler: showStatusBarMessageHandler
137150
}, {
@@ -140,13 +153,13 @@ export const notificationListeners : notificationOrRequestListenerType[] = [{
140153
}, {
141154
type: TestProgressNotification.type,
142155
handler: testProgressHandler
143-
},{
156+
}, {
144157
type: TextEditorDecorationSetNotification.type,
145158
handler: textEditorSetDecorationHandler
146-
},{
159+
}, {
147160
type: TextEditorDecorationDisposeNotification.type,
148161
handler: textEditorDecorationDisposeHandler
149-
},{
162+
}, {
150163
type: TelemetryEventNotification.type,
151164
handler: telemetryEventHandler
152165
}];

vscode/src/telemetry/events/jdkFeature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class JdkFeatureEvent extends BaseEvent<JdkFeatureEventData> {
4949
const names: string[] = [];
5050

5151
events.forEach(event => {
52-
jeps.push(...event.getPayload.jeps);
53-
names.push(...event.getPayload.names);
52+
if (event.getPayload.jeps) jeps.push(...event.getPayload.jeps);
53+
if (event.getPayload.names) names.push(...event.getPayload.names);
5454
});
5555

5656
return new JdkFeatureEvent({

0 commit comments

Comments
 (0)