Skip to content

Commit

Permalink
SLE-271 Use detected language of file for telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Oct 4, 2018
1 parent 4393fa7 commit ccd2b55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ public void analysisDoneOnMultipleFiles_should_not_trigger_analysisDoneOnMultipl
@Test
public void analysisDoneOnSingleFile_should_trigger_analysisDoneOnSingleFile_when_enabled() {
when(engine.isEnabled()).thenReturn(true);
String fileExtension = "java";
String language = "java";
int time = 123;
telemetry.analysisDoneOnSingleFile(fileExtension, time);
telemetry.analysisDoneOnSingleFile(language, time);
verify(engine).isEnabled();
verify(engine).analysisDoneOnSingleFile(fileExtension, time);
verify(engine).analysisDoneOnSingleLanguage(language, time);
}

@Test
public void analysisDoneOnSingleFile_should_not_trigger_analysisDoneOnSingleFile_when_disabled() {
when(engine.isEnabled()).thenReturn(false);
String fileExtension = "java";
String language = "java";
int time = 123;
telemetry.analysisDoneOnSingleFile(fileExtension, time);
telemetry.analysisDoneOnSingleFile(language, time);
verify(engine).isEnabled();
verifyNoMoreInteractions(engine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,27 +205,21 @@ private void runAnalysisAndUpdateMarkers(Map<ISonarLintFile, IDocument> docPerFi
AnalysisResults result = run(config, issuesPerResource, monitor);
if (!monitor.isCanceled()) {
updateMarkers(docPerFiles, issuesPerResource, result, triggerType, monitor);
updateTelemetry(inputFiles, start);
updateTelemetry(result, start);
}
}

protected abstract CONFIG prepareAnalysisConfig(Path projectBaseDir, List<ClientInputFile> inputFiles, Map<String, String> mergedExtraProps);

private static void updateTelemetry(List<ClientInputFile> inputFiles, long start) {
private static void updateTelemetry(AnalysisResults result, long start) {
SonarLintTelemetry telemetry = SonarLintCorePlugin.getTelemetry();
if (inputFiles.size() == 1) {
telemetry.analysisDoneOnSingleFile(getExtension(inputFiles.iterator().next()), (int) (System.currentTimeMillis() - start));
if (result.languagePerFile().size() == 1) {
telemetry.analysisDoneOnSingleFile(result.languagePerFile().entrySet().iterator().next().getValue(), (int) (System.currentTimeMillis() - start));
} else {
telemetry.analysisDoneOnMultipleFiles();
}
}

private static String getExtension(ClientInputFile next) {
String path = next.getPath();
int lastDot = path.lastIndexOf('.');
return lastDot >= 0 ? path.substring(lastDot + 1) : "";
}

private static List<ClientInputFile> buildInputFiles(Path tempDirectory, final Map<ISonarLintFile, IDocument> filesToAnalyze) {
List<ClientInputFile> inputFiles = new ArrayList<>(filesToAnalyze.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down Expand Up @@ -160,9 +161,9 @@ public void analysisDoneOnMultipleFiles() {
}
}

public void analysisDoneOnSingleFile(String fileExtension, int time) {
public void analysisDoneOnSingleFile(@Nullable String language, int time) {
if (enabled()) {
telemetry.analysisDoneOnSingleFile(fileExtension, time);
telemetry.analysisDoneOnSingleLanguage(language, time);
}
}

Expand Down

0 comments on commit ccd2b55

Please sign in to comment.