Skip to content

Commit dcb4a0e

Browse files
committed
feat: added feedback service (#73)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent dcd80bf commit dcb4a0e

30 files changed

+776
-278
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
testImplementation(
4040
"org.junit.jupiter:junit-jupiter:5.9.1",
4141
"org.junit.platform:junit-platform-launcher:1.9.1",
42-
"org.assertj:assertj-core:3.22.0",
42+
"org.assertj:assertj-core:3.24.2",
4343
"org.mockito:mockito-inline:4.5.1"
4444
)
4545
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ideaVersion = IC-2020.3
33
# https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
44
sinceIdeaBuild=203
55
projectVersion=1.0.1-SNAPSHOT
6-
intellijPluginVersion=1.13.3
6+
intellijPluginVersion=1.16.1
77
jetBrainsToken=invalid
88
jetBrainsChannel=stable
99
nexusUser=invalid

src/main/java/com/redhat/devtools/intellij/telemetry/core/IMessageBroker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
******************************************************************************/
1111
package com.redhat.devtools.intellij.telemetry.core;
1212

13-
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryEvent;
13+
import com.redhat.devtools.intellij.telemetry.core.service.Event;
1414

1515
public interface IMessageBroker {
16-
void send(TelemetryEvent event);
16+
void send(Event event);
1717
void dispose();
1818
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021 Red Hat, Inc.
2+
* Copyright (c) 2023 Red Hat, Inc.
33
* Distributed under license by Red Hat, Inc. All rights reserved.
44
* This program is made available under the terms of the
55
* Eclipse Public License v2.0 which accompanies this distribution,
@@ -10,8 +10,8 @@
1010
******************************************************************************/
1111
package com.redhat.devtools.intellij.telemetry.core;
1212

13-
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryEvent;
13+
import com.redhat.devtools.intellij.telemetry.core.service.Event;
1414

15-
public interface ITelemetryService {
16-
void send(TelemetryEvent event);
15+
public interface IService {
16+
void send(Event event);
1717
}

src/main/java/com/redhat/devtools/intellij/telemetry/core/service/TelemetryEvent.java renamed to src/main/java/com/redhat/devtools/intellij/telemetry/core/service/Event.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021 Red Hat, Inc.
2+
* Copyright (c) 2023 Red Hat, Inc.
33
* Distributed under license by Red Hat, Inc. All rights reserved.
44
* This program is made available under the terms of the
55
* Eclipse Public License v2.0 which accompanies this distribution,
@@ -13,7 +13,7 @@
1313
import java.util.HashMap;
1414
import java.util.Map;
1515

16-
public class TelemetryEvent {
16+
public class Event {
1717

1818
public enum Type {
1919
USER, ACTION, STARTUP, SHUTDOWN
@@ -23,11 +23,11 @@ public enum Type {
2323
private final String name;
2424
private final Map<String, String> properties;
2525

26-
public TelemetryEvent(Type type, String name) {
26+
public Event(Type type, String name) {
2727
this(type, name, new HashMap<>());
2828
}
2929

30-
public TelemetryEvent(Type type, String name, Map<String, String> properties) {
30+
public Event(Type type, String name, Map<String, String> properties) {
3131
this.type = type;
3232
this.name = name;
3333
this.properties = properties;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.telemetry.core.service;
12+
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
public class FeedbackEvent extends Event {
17+
18+
public FeedbackEvent(String name) {
19+
this(name, new HashMap<>());
20+
}
21+
22+
public FeedbackEvent(String name, Map<String, String> properties) {
23+
super(Type.ACTION, name, properties);
24+
}
25+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.telemetry.core.service;
12+
13+
import com.intellij.openapi.application.ApplicationManager;
14+
import com.intellij.openapi.diagnostic.Logger;
15+
import com.redhat.devtools.intellij.telemetry.core.IService;
16+
import com.redhat.devtools.intellij.telemetry.core.util.Lazy;
17+
18+
import java.util.function.Supplier;
19+
20+
import static com.redhat.devtools.intellij.telemetry.core.service.Event.Type.ACTION;
21+
22+
public class FeedbackMessageBuilder {
23+
24+
private static final Logger LOGGER = Logger.getInstance(FeedbackMessageBuilder.class);
25+
26+
private final IService serviceFacade;
27+
28+
public FeedbackMessageBuilder(ClassLoader classLoader) {
29+
this(new FeedbackServiceFacade(classLoader));
30+
}
31+
32+
FeedbackMessageBuilder(IService serviceFacade) {
33+
this.serviceFacade = serviceFacade;
34+
}
35+
36+
static class FeedbackServiceFacade extends Lazy<IService> implements IService {
37+
38+
protected FeedbackServiceFacade(final ClassLoader classLoader) {
39+
this(() -> ApplicationManager.getApplication().getService(FeedbackServiceFactory.class).create(classLoader));
40+
}
41+
42+
protected FeedbackServiceFacade(final Supplier<IService> supplier) {
43+
super(supplier);
44+
}
45+
46+
@Override
47+
public void send(Event event) {
48+
get().send(event);
49+
}
50+
}
51+
52+
public FeedbackMessage feedback(String name) {
53+
return new FeedbackMessage(name, serviceFacade);
54+
}
55+
56+
public static class FeedbackMessage extends Message<FeedbackMessage>{
57+
58+
private FeedbackMessage(String name, IService service) {
59+
super(ACTION, name, service);
60+
}
61+
}
62+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.telemetry.core.service;
12+
13+
import com.intellij.openapi.diagnostic.Logger;
14+
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker;
15+
import com.redhat.devtools.intellij.telemetry.core.IService;
16+
17+
public class FeedbackService implements IService {
18+
19+
private static final Logger LOGGER = Logger.getInstance(FeedbackService.class);
20+
21+
protected final IMessageBroker broker;
22+
23+
public FeedbackService(final IMessageBroker broker) {
24+
this.broker = broker;
25+
}
26+
27+
@Override
28+
public void send(Event event) {
29+
broker.send(event);
30+
}
31+
32+
public void dispose() {
33+
broker.dispose();
34+
}
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.telemetry.core.service;
12+
13+
import com.intellij.openapi.project.DumbAware;
14+
import com.redhat.devtools.intellij.telemetry.core.IMessageBroker;
15+
import com.redhat.devtools.intellij.telemetry.core.IService;
16+
import com.redhat.devtools.intellij.telemetry.core.configuration.TelemetryConfiguration;
17+
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentBroker;
18+
import com.redhat.devtools.intellij.telemetry.core.service.segment.SegmentConfiguration;
19+
20+
public class FeedbackServiceFactory implements DumbAware {
21+
22+
public IService create(ClassLoader classLoader) {
23+
TelemetryConfiguration configuration = TelemetryConfiguration.getInstance();
24+
IMessageBroker broker = createSegmentBroker(configuration.isDebug(), classLoader);
25+
return new FeedbackService(broker);
26+
}
27+
28+
private IMessageBroker createSegmentBroker(boolean isDebug, ClassLoader classLoader) {
29+
SegmentConfiguration brokerConfiguration = new SegmentConfiguration(classLoader);
30+
return new SegmentBroker(
31+
isDebug,
32+
UserId.INSTANCE.get(),
33+
null,
34+
brokerConfiguration);
35+
}
36+
37+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.telemetry.core.service;
12+
13+
import com.intellij.openapi.diagnostic.Logger;
14+
import com.redhat.devtools.intellij.telemetry.core.IService;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
19+
abstract class Message<T extends Message> {
20+
21+
private static final Logger LOGGER = Logger.getInstance(Message.class);
22+
23+
private final Event.Type type;
24+
private final Map<String, String> properties = new HashMap<>();
25+
private final String name;
26+
private final IService service;
27+
28+
protected Message(Event.Type type, String name, IService service) {
29+
this.name = name;
30+
this.type = type;
31+
this.service = service;
32+
}
33+
34+
String getName() {
35+
return name;
36+
}
37+
38+
Event.Type getType() {
39+
return type;
40+
}
41+
42+
public T property(String key, String value) {
43+
if (key == null
44+
|| value == null) {
45+
LOGGER.warn("Ignored property with key: " + key + " value: " + value);
46+
} else {
47+
properties.put(key, value);
48+
}
49+
return (T) this;
50+
}
51+
52+
String getProperty(String key) {
53+
return properties.get(key);
54+
}
55+
56+
Map<String, String> properties() {
57+
return properties;
58+
}
59+
60+
protected boolean hasProperty(String key) {
61+
return properties.containsKey(key);
62+
}
63+
64+
public Event send() {
65+
Event event = new Event(type, name, new HashMap<>(properties));
66+
service.send(event);
67+
return event;
68+
}
69+
}

0 commit comments

Comments
 (0)