Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added feedback service (#73) #74

Merged
merged 5 commits into from
Dec 18, 2023
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
6 changes: 6 additions & 0 deletions .github/workflows/IJ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
jvm: 17
- IJ: IC-2022.3
jvm: 17
- IJ: IC-2023.1
jvm: 17
- IJ: IC-2023.2
jvm: 17
- IJ: IC-2023.3
jvm: 17

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
testImplementation(
"org.junit.jupiter:junit-jupiter:5.9.1",
"org.junit.platform:junit-platform-launcher:1.9.1",
"org.assertj:assertj-core:3.22.0",
"org.assertj:assertj-core:3.24.2",
"org.mockito:mockito-inline:4.5.1"
)
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ideaVersion = IC-2020.3
# build number ranges
# https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
sinceIdeaBuild=203
projectVersion=1.0.1-SNAPSHOT
intellijPluginVersion=1.13.3
projectVersion=1.1.0-SNAPSHOT
intellijPluginVersion=1.16.1
jetBrainsToken=invalid
jetBrainsChannel=stable
nexusUser=invalid
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
******************************************************************************/
package com.redhat.devtools.intellij.telemetry.core;

import com.redhat.devtools.intellij.telemetry.core.service.TelemetryEvent;
import com.redhat.devtools.intellij.telemetry.core.service.Event;

public interface IMessageBroker {
void send(TelemetryEvent event);
void send(Event event);
void dispose();

interface IMessageBrokerFactory {
IMessageBroker create(boolean isDebug, ClassLoader classLoader);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Copyright (c) 2023 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,
Expand All @@ -10,8 +10,8 @@
******************************************************************************/
package com.redhat.devtools.intellij.telemetry.core;

import com.redhat.devtools.intellij.telemetry.core.service.TelemetryEvent;
import com.redhat.devtools.intellij.telemetry.core.service.Event;

public interface ITelemetryService {
void send(TelemetryEvent event);
public interface IService {
void send(Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void ensureCountry() {
}
}

class Buildable {
public class Buildable {
public Environment build() {
ensureIDE();
ensurePlatform();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Copyright (c) 2023 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,
Expand All @@ -13,7 +13,7 @@
import java.util.HashMap;
import java.util.Map;

public class TelemetryEvent {
public class Event {

public enum Type {
USER, ACTION, STARTUP, SHUTDOWN
Expand All @@ -23,11 +23,11 @@ public enum Type {
private final String name;
private final Map<String, String> properties;

public TelemetryEvent(Type type, String name) {
public Event(Type type, String name) {
this(type, name, new HashMap<>());
}

public TelemetryEvent(Type type, String name, Map<String, String> properties) {
public Event(Type type, String name, Map<String, String> properties) {
this.type = type;
this.name = name;
this.properties = properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2023 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 com.redhat.devtools.intellij.telemetry.core.service;

import com.intellij.openapi.diagnostic.Logger;
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker;
import com.redhat.devtools.intellij.telemetry.core.IService;

public class FeedbackService implements IService {

private static final Logger LOGGER = Logger.getInstance(FeedbackService.class);

protected final IMessageBroker broker;

public FeedbackService(final IMessageBroker broker) {
this.broker = broker;
}

@Override
public void send(Event event) {
broker.send(event);
}

public void dispose() {
broker.dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2023 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 com.redhat.devtools.intellij.telemetry.core.service;

import com.intellij.openapi.project.DumbAware;
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker;
import com.redhat.devtools.intellij.telemetry.core.IService;
import com.redhat.devtools.intellij.telemetry.core.configuration.TelemetryConfiguration;
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentBroker;
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentConfiguration;

public class FeedbackServiceFactory implements DumbAware {

public IService create(IMessageBroker broker) {
return new FeedbackService(broker);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*******************************************************************************
* Copyright (c) 2023 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 com.redhat.devtools.intellij.telemetry.core.service;

import com.intellij.openapi.diagnostic.Logger;
import com.redhat.devtools.intellij.telemetry.core.IService;

import java.util.HashMap;
import java.util.Map;

import static com.redhat.devtools.intellij.telemetry.core.util.AnonymizeUtils.anonymize;

abstract class Message<T extends Message<?>> {

private static final Logger LOGGER = Logger.getInstance(Message.class);

static final String PROP_RESULT = "result";

public static final String RESULT_SUCCESS = "success";

public static final String RESULT_ABORTED = "aborted";

static final String PROP_ERROR = "error";

private final Event.Type type;
private final Map<String, String> properties = new HashMap<>();
private final String name;
private final IService service;

protected Message(Event.Type type, String name, IService service) {
this.name = name;
this.type = type;
this.service = service;
}

String getName() {
return name;
}

Event.Type getType() {
return type;
}

String getError() {
return getProperty(PROP_ERROR);
}

public T error(Exception exception) {
if (exception == null) {
return (T) this;
}
return error(exception.getMessage());
}

public T error(String message) {
property(PROP_ERROR, anonymize(message));
return clearResult();
}

protected T clearError() {
properties().remove(PROP_ERROR);
return (T) this;
}

String getResult() {
return getProperty(PROP_RESULT);
}

public T result(String result) {
property(PROP_RESULT, result);
return clearError();
}

public T success() {
return result(RESULT_SUCCESS);
}

public T aborted() {
return result(RESULT_ABORTED);
}

protected T clearResult() {
properties().remove(PROP_RESULT);
return (T) this;
}

public T property(String key, String value) {
if (key == null
|| value == null) {
LOGGER.warn("Ignored property with key: " + key + " value: " + value);
} else {
properties.put(key, value);
}
return (T) this;
}

String getProperty(String key) {
return properties.get(key);
}

Map<String, String> properties() {
return properties;
}

protected boolean hasProperty(String key) {
return properties.containsKey(key);
}

public Event send() {
Event event = new Event(type, name, new HashMap<>(properties));
service.send(event);
return event;
}
}
Loading
Loading