Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions USAGE_DATA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## [Dependency Analytics](https://github.com/redhat-developer/intellij-dependency-analytics)

### Usage Data

* when plugin is started
* when server is downloaded
* when a component analysis is done
* when plugin is shut down

9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ targetCompatibility = '1.8'
intellij {
version ideaVersion //for a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases
pluginName 'org.jboss.tools.intellij.analytics'
plugins 'com.redhat.devtools.intellij.telemetry:0.0.1.9'
updateSinceUntilBuild false
}

Expand All @@ -39,5 +40,13 @@ dependencies {
testImplementation("junit:junit:4.12")
}

runIde {
systemProperties['com.redhat.devtools.intellij.telemetry.mode'] = 'debug'
}

runIdeForUiTests {
systemProperties['com.redhat.devtools.intellij.telemetry.mode'] = 'debug'
}

group 'org.jboss.tools.intellij'
version projectVersion // Plugin version
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,49 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.jetbrains.annotations.NotNull;
import org.wso2.lsp4intellij.client.ClientContext;
import org.wso2.lsp4intellij.client.DefaultLanguageClient;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Map;

public class AnalyticsLanguageClient extends DefaultLanguageClient {
public AnalyticsLanguageClient(@NotNull ClientContext context) {
super(context);
}

private static String getFilename(Map<String, Object> info) {
String filename = null;
String url = (String) info.get("uri");
if (url != null) {
try {
filename = Paths.get(new URI(url)).getFileName().toString();
} catch (URISyntaxException e) {}
}
return filename;
}

@JsonNotification("caNotification")
public void caNotify(Object payload) {
if (payload instanceof Map) {
Map<String, Object> info = (Map<String, Object>) payload;
if (info.containsKey("data") && info.containsKey("diagCount")) {
ActionMessage telemetry = TelemetryService.instance().action("lsp:component_analysis_done");
String filename = getFilename(info);
if (filename != null) {
telemetry.property("filename", filename);
}
telemetry.send();
Notifications.Bus.notify(new Notification("Analytics", "Analytics", (String) info.get("data"), NotificationType.INFORMATION));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.util.io.HttpRequests;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class GitHubReleaseDownloader {
private static Logger LOGGER = LoggerFactory.getLogger(GitHubReleaseDownloader.class);
private final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("org.jboss.tools.intellij.analytics"));
private final String fileName;
private final ICookie cookies;
Expand All @@ -37,14 +41,22 @@ public File download(final ProgressIndicator indicator) throws IOException {
if (!isNewRelease(latestReleaseTag) && dest.exists()) {
return dest;
}
final String url = this.release.getDownloadUri(latestReleaseTag, this.fileName);
HttpRequests
.request(url)
.productNameAsUserAgent()
.saveToFile(dest, indicator);
final ActionMessage telemetry = TelemetryService.instance().action("lsp:download").property("lspVersion", latestReleaseTag);
try {
final String url = this.release.getDownloadUri(latestReleaseTag, this.fileName);
HttpRequests
.request(url)
.productNameAsUserAgent()
.saveToFile(dest, indicator);

dest.setExecutable(true);
cookies.setValue(ICookie.Name.LSPVersion, latestReleaseTag);
return dest;
dest.setExecutable(true);
cookies.setValue(ICookie.Name.LSPVersion, latestReleaseTag);
telemetry.send();
return dest;
} catch (IOException e) {
telemetry.error(e).send();
LOGGER.warn(e.getLocalizedMessage(), e);
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.analytics;

import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import com.redhat.devtools.intellij.telemetry.core.util.Lazy;

public class TelemetryService {
private static final TelemetryService INSTANCE = new TelemetryService();

private final Lazy<TelemetryMessageBuilder> builder = new Lazy<>(() -> new TelemetryMessageBuilder(TelemetryService.class.getClassLoader()));

public static TelemetryMessageBuilder instance() {
return INSTANCE.builder.get();
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<depends>com.intellij.modules.lang</depends>
<depends>com.redhat.devtools.intellij.telemetry</depends>

<extensions defaultExtensionNs="com.intellij">
<externalAnnotator id="LSPAnnotator-xml" language="XML" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
Expand Down