Skip to content

Commit eff8dde

Browse files
committed
Merge
2 parents 71b4a3f + 536de97 commit eff8dde

32 files changed

+460
-150
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Changelog
22

3-
## [2.0.328] - 2024-05-01
3+
## [2.0.331] - 2024-05-09
4+
5+
- clear current env when deleting last env Closes #2139 by @shalom938
6+
in https://github.com/digma-ai/digma-intellij-plugin/pull/2140
7+
- put jars urls in properties file by @shalom938 in https://github.com/digma-ai/digma-intellij-plugin/pull/2147
8+
9+
## 2.0.330 - 2024-05-06
10+
11+
- Update Digmathon by @kshmidt-digma in https://github.com/digma-ai/digma-intellij-plugin/pull/2134
12+
13+
## 2.0.329 - 2024-05-05
14+
15+
- prevent posthog errors when can't connect Closes #2041 by @shalom938
16+
in https://github.com/digma-ai/digma-intellij-plugin/pull/2137
17+
- don't log NoSelectedEnvironmentException in warn level Closes #2136 by @shalom938
18+
in https://github.com/digma-ai/digma-intellij-plugin/pull/2138
19+
20+
## 2.0.328 - 2024-05-01
421

522
- remove some info from settings events Closes #2013 by @shalom938 in https://github.com/digma-ai/digma-intellij-plugin/pull/2127
623
- update build profiles by @shalom938 in https://github.com/digma-ai/digma-intellij-plugin/pull/2131

ide-common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
api(libs.maven.artifact)
3232
api(libs.glovoapp.versioning)
3333
api(libs.byte.buddy)
34+
api(libs.jackson.datetime)
3435

3536

3637
implementation(project(":model"))

ide-common/src/main/java/org/digma/intellij/plugin/analytics/Environment.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void setCurrentById(@NotNull String envId, @Nullable Runnable taskToRunAfterChan
6767
try {
6868
Log.log(LOGGER::debug, "Setting current environment by id , old={},new={}", current, envId);
6969

70-
if (StringUtils.isEmpty(envId)) {
70+
if (StringUtils.isEmpty(envId) || StringUtils.isBlank(envId)) {
7171
Log.log(LOGGER::debug, "setCurrent was called with an empty environment {}", envId);
7272
return;
7373
}
@@ -174,12 +174,18 @@ private void updateCurrentEnv(@Nullable String preferred) {
174174
var oldEnv = current;
175175

176176
var optionalEnv = find(preferred);
177-
if (optionalEnv.isPresent()) {
178-
current = optionalEnv.get();
179-
} else if (current == null) {
180-
current = environments.isEmpty() ? null : environments.get(0);
181-
}
182-
177+
current = optionalEnv.orElseGet(() -> environments.isEmpty() ? null : environments.get(0));
178+
179+
//latestKnownEnvId is updated only if current is not null.
180+
//current will be null on connection lost, or when the last env was deleted. actually when the
181+
// environments list is empty, this code can't distinguish between these two cases.
182+
// so if current is null we keep latestKnownEnvId with its current value. if connection was
183+
// lost and gained it will help restore the current env. if the environments list was empty
184+
// because the last env was deleted then it will keep a value of the latest that actually
185+
// does not exist, but it will change on the first new environment.
186+
//the persistence is changed to null if current is null. on connection lost it will be set
187+
// back with value after connection gained. and if the last env was deleted it will be set
188+
// back with value when a new environment is added.
183189
if (current != null) {
184190
latestKnownEnvId = current.getId();
185191
PersistenceService.getInstance().setLatestSelectedEnvId(latestKnownEnvId);

ide-common/src/main/java/org/digma/intellij/plugin/common/EDT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void assertEDT(String message) {
3636
}
3737
//log an error here, intellij will pop up an error message. usually we don't want an error message
3838
// but this should be caught in development time.
39-
Log.log(LOGGER::error,message);
39+
LOGGER.error(message);
4040
}
4141

4242

ide-common/src/main/java/org/digma/intellij/plugin/log/Log.java

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.openapi.diagnostic.Logger;
44
import com.intellij.openapi.project.Project;
5+
import org.digma.intellij.plugin.analytics.NoSelectedEnvironmentException;
56
import org.digma.intellij.plugin.errorreporting.*;
67

78
import java.time.Duration;
@@ -18,7 +19,7 @@ public class Log {
1819
public static final String API_LOGGER_NAME = "api.digma.org";
1920

2021

21-
private static final FrequentErrorDetector FREQUENT_ERROR_DETECTOR = new FrequentErrorDetector(Duration.ofMinutes(10));
22+
private static final FrequentErrorDetector FREQUENT_ERROR_DETECTOR = new FrequentErrorDetector(Duration.ofMinutes(30));
2223

2324

2425

@@ -31,6 +32,11 @@ public static void log(Consumer<String> consumer, String format, Object... args)
3132
}
3233

3334
public static void debugWithException(Logger logger,Throwable e, String format, Object... args) {
35+
36+
if (!logger.isDebugEnabled()) {
37+
return;
38+
}
39+
3440
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
3541
return;
3642
}
@@ -39,24 +45,43 @@ public static void debugWithException(Logger logger,Throwable e, String format,
3945
}
4046

4147
public static void debugWithException(Logger logger, Project project,Throwable e, String format, Object... args) {
48+
49+
if (!logger.isDebugEnabled()) {
50+
return;
51+
}
52+
4253
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
4354
return;
4455
}
56+
4557
logger.debug(DIGMA_PROJECT + project.getName() + ": " + String.format(format.replace("{}", "%s"), args),e);
4658
}
4759

60+
4861
public static void warnWithException(Logger logger,Throwable e, String format, Object... args) {
49-
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
50-
return;
62+
63+
//don't log NoSelectedEnvironmentException in warn level
64+
if (e instanceof NoSelectedEnvironmentException) {
65+
debugWithException(logger, e, format, args);
66+
} else {
67+
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
68+
return;
69+
}
70+
logger.warn(DIGMA + String.format(format.replace("{}", "%s"), args), e);
5171
}
52-
logger.warn(DIGMA + String.format(format.replace("{}", "%s"), args),e);
5372
}
5473

5574
public static void warnWithException(Logger logger, Project project,Throwable e, String format, Object... args) {
56-
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
57-
return;
75+
76+
//don't log NoSelectedEnvironmentException in warn level
77+
if (e instanceof NoSelectedEnvironmentException) {
78+
debugWithException(logger, project, e, format, args);
79+
} else {
80+
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, e)) {
81+
return;
82+
}
83+
logger.warn(DIGMA_PROJECT + project.getName() + ": " + String.format(format.replace("{}", "%s"), args), e);
5884
}
59-
logger.warn(DIGMA_PROJECT + project.getName() + ": " + String.format(format.replace("{}", "%s"), args),e);
6085
}
6186

6287

@@ -68,30 +93,40 @@ public static void log(Consumer<String> consumer, String msg) {
6893
consumer.accept(DIGMA + msg);
6994
}
7095

71-
public static void error(Logger logger,Project project, Exception exception, String format, Object... args) {
72-
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, exception)) {
73-
return;
74-
}
7596

76-
var msg = String.format(format.replace("{}", "%s"), args);
77-
error(logger, exception, DIGMA_PROJECT + project.getName() + ": " + msg);
78-
ErrorReporter.getInstance().reportError(project, "Log.error", exception);
97+
//Note: We should never log error in intellij because logging error will popup a red error to the user.
98+
99+
private static void error(Logger logger, Project project, Exception exception, String format, Object... args) {
100+
101+
if (exception instanceof NoSelectedEnvironmentException) {
102+
debugWithException(logger, exception, format, args);
103+
} else {
104+
105+
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, exception)) {
106+
return;
107+
}
108+
109+
var msg = String.format(format.replace("{}", "%s"), args);
110+
error(logger, exception, DIGMA_PROJECT + project.getName() + ": " + msg);
111+
ErrorReporter.getInstance().reportError(project, "Log.error", exception);
112+
}
79113
}
80-
public static void error(Logger logger, Exception exception, String format, Object... args) {
114+
115+
private static void error(Logger logger, Exception exception, String format, Object... args) {
81116
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(format, exception)) {
82117
return;
83118
}
84119
error(logger, exception, DIGMA + String.format(format.replace("{}", "%s"), args));
85120
}
86121

87-
public static void error(Logger logger, Exception exception, String msg) {
122+
private static void error(Logger logger, Exception exception, String msg) {
88123
if (FREQUENT_ERROR_DETECTOR.isTooFrequentException(msg, exception)) {
89124
return;
90125
}
91126
logger.error(DIGMA + msg, exception);
92127
}
93128

94-
public static void error(Logger logger, String msg) {
129+
private static void error(Logger logger, String msg) {
95130
logger.error(DIGMA + msg);
96131
}
97132

ide-common/src/main/kotlin/org/digma/intellij/plugin/common/ObjectMapperFactory.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,37 @@ package org.digma.intellij.plugin.common
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.databind.SerializationFeature
55
import com.fasterxml.jackson.databind.util.StdDateFormat
6+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
67

78

89
/**
910
* a factory for ObjectMapper to be used by components and services that need an ObjectMapper,
1011
* makes sure all will use the same configuration.
1112
*/
1213
fun createObjectMapper(): ObjectMapper {
14+
//Note that it is risky to change configuration or install modules.
15+
// because there are components that already use this object mapper as is
16+
// and changes to configuration may cause issues. its probably mainly dates that were
17+
// serialized to persistence.
18+
//but, probably installing the JavaTimeModule should be OK because it's backwards compatible.
19+
//users of this factory may change configuration on the instance they create.
1320
val objectMapper = ObjectMapper()
1421
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
1522
objectMapper.setDateFormat(StdDateFormat())
1623
return objectMapper
1724
}
1825

26+
27+
fun createObjectMapperWithJavaTimeModule(): ObjectMapper {
28+
//install the JavaTimeModule for better serialization of dates
29+
val objectMapper = ObjectMapper()
30+
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
31+
objectMapper.registerModules(JavaTimeModule())
32+
objectMapper.setDateFormat(StdDateFormat())
33+
return objectMapper
34+
}
35+
36+
1937
/**
2038
* ObjectMapper is fully thread safe and does not need to be created many times.
2139
* usually its more convenient to create a class member in classes that need to use an ObjectMapper

ide-common/src/main/kotlin/org/digma/intellij/plugin/digmathon/DigmathonProductKey.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import java.nio.charset.StandardCharsets
99

1010

1111
private const val MY_SERVICE = "org.digma.digmathon.productKey"
12-
private const val MY_KEY = "product-key-2024.4"
12+
13+
//change MY_KEY for every new dismathon
14+
private const val MY_KEY = "product-key-2024.5"
1315

1416
class DigmathonProductKey {
1517

16-
private val myHash = "b9fe040958b98f68533511125bc104435bfefd4293b328060992767d51333321"
18+
private val myHash = "89e0f23f9a0a670b2bb7393a1280aa59eaf7c59c22b77d869b5c9c7af021785f"
1719

1820
@Throws(InvalidProductKeyException::class)
1921
fun validateAndSave(productKey: String) {

0 commit comments

Comments
 (0)