diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildClient.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildClient.java index c425fe70c..fccb741f6 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildClient.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildClient.java @@ -57,7 +57,6 @@ public class GradleBuildClient implements BuildClient { /** * Client command to send telemetry data to the LS client. */ - private static final String CLIENT_BUILD_SEND_TELEMETRY = "_java.gradle.buildServer.sendTelemetry"; private final JavaLanguageClient lsClient; @@ -68,8 +67,12 @@ public GradleBuildClient() { @Override public void onBuildLogMessage(LogMessageParams params) { MessageType type = params.getType(); - String cmd = type == MessageType.LOG ? CLIENT_BUILD_SEND_TELEMETRY : CLIENT_BUILD_LOG_CMD; - this.lsClient.sendNotification(new ExecuteCommandParams(cmd, Arrays.asList(params.getMessage()))); + if (type == MessageType.LOG) { + Utils.sendTelemetry(this.lsClient, params.getMessage()); + } else { + this.lsClient.sendNotification(new ExecuteCommandParams(CLIENT_BUILD_LOG_CMD, + Arrays.asList(params.getMessage()))); + } } @Override diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java index 452bd3c5d..dc1e260cf 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java @@ -31,9 +31,9 @@ import org.eclipse.jdt.ls.core.internal.managers.BasicFileDetector; import org.eclipse.jdt.ls.core.internal.managers.DigestStore; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; - import com.microsoft.java.builder.JavaProblemChecker; import com.microsoft.gradle.bs.importer.model.BuildServerPreferences; +import com.microsoft.gradle.bs.importer.model.Telemetry; import ch.epfl.scala.bsp4j.BuildClientCapabilities; import ch.epfl.scala.bsp4j.BuildTarget; @@ -85,6 +85,9 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti .addExclusions("**/bin"); Collection androidDirectories = androidDetector.scan(monitor); if (!androidDirectories.isEmpty()) { + Telemetry telemetry = new Telemetry("hasAndroidManifest", "true"); + Utils.sendTelemetry(JavaLanguageServerPlugin.getProjectsManager().getConnection(), + telemetry); return false; } diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/Utils.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/Utils.java index 1e993697d..fd312aee6 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/Utils.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/Utils.java @@ -21,8 +21,10 @@ import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.URIUtil; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient; import org.eclipse.jdt.ls.core.internal.ProjectUtils; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; +import org.eclipse.lsp4j.ExecuteCommandParams; import com.microsoft.gradle.bs.importer.builder.BuildServerBuilder; @@ -207,4 +209,9 @@ public static boolean isBuildServerEnabled(Preferences preferences) { String bspImporterEnabled = getString(preferences.asMap(), JAVA_BUILD_SERVER_GRADLE_ENABLED); return "on".equalsIgnoreCase(bspImporterEnabled); } + + public static void sendTelemetry(JavaLanguageClient client, Object message) { + client.sendNotification(new ExecuteCommandParams("_java.gradle.buildServer.sendTelemetry", + Arrays.asList(message))); + } } diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/Telemetry.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/Telemetry.java new file mode 100644 index 000000000..f41a1cf15 --- /dev/null +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/Telemetry.java @@ -0,0 +1,5 @@ +package com.microsoft.gradle.bs.importer.model; + +public record Telemetry(String kind, Object data) { + +} diff --git a/extension/src/bs/BuildServerController.ts b/extension/src/bs/BuildServerController.ts index 0252299bf..5c91feaee 100644 --- a/extension/src/bs/BuildServerController.ts +++ b/extension/src/bs/BuildServerController.ts @@ -59,12 +59,20 @@ export class BuildServerController implements Disposable { this.logOutputChannel.appendLine(msg); } }), - commands.registerCommand(SEND_TELEMETRY_CMD, (jsonString: string) => { - const log = JSON.parse(jsonString); + commands.registerCommand(SEND_TELEMETRY_CMD, (data: string | object) => { + let jsonString: string; + let jsonObj: { [key: string]: any}; + if (typeof data === "string") { + jsonObj = JSON.parse(data); + jsonString = data; + } else { + jsonObj = data; + jsonString = JSON.stringify(data); + } sendInfo("", { - kind: log.kind, + kind: jsonObj.kind, data: jsonString, - ...(log.schemaVersion && { schemaVersion: log.schemaVersion }), + ...(jsonObj.schemaVersion && { schemaVersion: jsonObj.schemaVersion }), }); }), workspace.onDidChangeConfiguration((e: ConfigurationChangeEvent) => {