Skip to content

Commit

Permalink
fix: Track if the workspace contains android manifest (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Oct 24, 2023
1 parent 4c107d6 commit 205f273
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,6 +85,9 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
.addExclusions("**/bin");
Collection<java.nio.file.Path> androidDirectories = androidDetector.scan(monitor);
if (!androidDirectories.isEmpty()) {
Telemetry telemetry = new Telemetry("hasAndroidManifest", "true");
Utils.sendTelemetry(JavaLanguageServerPlugin.getProjectsManager().getConnection(),
telemetry);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.microsoft.gradle.bs.importer.model;

public record Telemetry(String kind, Object data) {

}
16 changes: 12 additions & 4 deletions extension/src/bs/BuildServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Check warning on line 64 in extension/src/bs/BuildServerController.ts

View workflow job for this annotation

GitHub Actions / Build & Analyse

Unexpected any. Specify a different type
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) => {
Expand Down

0 comments on commit 205f273

Please sign in to comment.