Skip to content

Commit 6efd23c

Browse files
vaadin-botArtur-
andauthored
chore: Log used IDE (#21028) (#21037)
* chore: Log used IDE * Fix test Co-authored-by: Artur <[email protected]>
1 parent 8587591 commit 6efd23c

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

flow-test-generic/src/main/java/com/vaadin/flow/testutil/ClassesSerializableTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected Stream<String> getExcludedPatterns() {
8686
"com\\.vaadin\\.base\\.devserver\\.ExternalDependencyWatcher",
8787
"com\\.vaadin\\.base\\.devserver\\.FileWatcher",
8888
"com\\.vaadin\\.base\\.devserver\\.IdeIntegration",
89-
"com\\.vaadin\\.base\\.devserver\\.OpenInCurrentIde",
89+
"com\\.vaadin\\.base\\.devserver\\.OpenInCurrentIde.*",
9090
"com\\.vaadin\\.base\\.devserver\\.RestartMonitor",
9191
"com\\.vaadin\\.base\\.devserver\\.ThemeLiveUpdater",
9292
"com\\.vaadin\\.base\\.devserver\\.editor..*",

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/OpenInCurrentIde.java

+43-15
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,30 @@ private OpenInCurrentIde() {
6262
public static boolean openFile(File file, int lineNumber) {
6363
String absolutePath = file.getAbsolutePath();
6464

65-
Optional<Info> maybeIdeCommand = findIdeCommandInfo();
66-
if (!maybeIdeCommand.isPresent()) {
67-
getLogger().debug("Unable to detect IDE from process tree");
68-
printProcessTree(msg -> getLogger().debug(msg));
69-
return false;
70-
}
71-
72-
Info processInfo = maybeIdeCommand.get();
73-
74-
if (isVSCode(processInfo)) {
65+
IdeAndProcessInfo ideInfo = getIdeAndProcessInfo();
66+
if (ideInfo.ide == Ide.VSCODE) {
7567
return Open.open("vscode://file" + absolutePath + ":" + lineNumber);
76-
} else if (isIdea(processInfo)) {
68+
} else if (ideInfo.ide == Ide.INTELLIJ) {
7769
try {
78-
run(getBinary(processInfo), "--line", lineNumber + "",
70+
run(getBinary(ideInfo.processInfo), "--line", lineNumber + "",
7971
absolutePath);
8072
return true;
8173
} catch (Exception e) {
8274
getLogger().error("Unable to launch IntelliJ IDEA", e);
8375
}
8476

85-
} else if (isEclipse(processInfo)) {
77+
} else if (ideInfo.ide == Ide.ECLIPSE) {
8678
if (OSUtils.isMac()) {
8779
try {
88-
run("open", "-a", getBinary(processInfo), absolutePath);
80+
run("open", "-a", getBinary(ideInfo.processInfo),
81+
absolutePath);
8982
return true;
9083
} catch (Exception e) {
9184
getLogger().error("Unable to launch Eclipse", e);
9285
}
9386
} else {
9487
try {
95-
run(getBinary(processInfo),
88+
run(getBinary(ideInfo.processInfo),
9689
absolutePath + ":" + lineNumber);
9790
return true;
9891
} catch (Exception e) {
@@ -105,6 +98,41 @@ public static boolean openFile(File file, int lineNumber) {
10598

10699
}
107100

101+
public enum Ide {
102+
ECLIPSE, VSCODE, INTELLIJ, OTHER
103+
}
104+
105+
public record IdeAndProcessInfo(Ide ide, Info processInfo) {
106+
}
107+
108+
/**
109+
* Gets the IDE and process info for the current process.
110+
*
111+
* @return the IDE and process info
112+
*/
113+
public static IdeAndProcessInfo getIdeAndProcessInfo() {
114+
Optional<Info> maybeIdeCommand = findIdeCommandInfo();
115+
if (!maybeIdeCommand.isPresent()) {
116+
getLogger().debug("Unable to detect IDE from process tree");
117+
printProcessTree(msg -> getLogger().debug(msg));
118+
return new IdeAndProcessInfo(Ide.OTHER, null);
119+
}
120+
121+
Info processInfo = maybeIdeCommand.get();
122+
123+
Ide ide;
124+
if (isVSCode(processInfo)) {
125+
ide = Ide.VSCODE;
126+
} else if (isIdea(processInfo)) {
127+
ide = Ide.INTELLIJ;
128+
} else if (isEclipse(processInfo)) {
129+
ide = Ide.ECLIPSE;
130+
} else {
131+
ide = Ide.OTHER;
132+
}
133+
return new IdeAndProcessInfo(ide, processInfo);
134+
}
135+
108136
static String getBinary(Info info) {
109137
String cmd = info.command().get();
110138
if (isIdea(info)) {

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/startup/DevModeInitializer.java

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Enumeration;
3737
import java.util.HashSet;
3838
import java.util.List;
39+
import java.util.Locale;
3940
import java.util.Set;
4041
import java.util.concurrent.CompletableFuture;
4142
import java.util.concurrent.CompletionException;
@@ -51,6 +52,7 @@
5152
import org.slf4j.LoggerFactory;
5253

5354
import com.vaadin.base.devserver.DevBundleBuildingHandler;
55+
import com.vaadin.base.devserver.OpenInCurrentIde;
5456
import com.vaadin.base.devserver.ViteHandler;
5557
import com.vaadin.base.devserver.stats.DevModeUsageStatistics;
5658
import com.vaadin.base.devserver.stats.StatisticsSender;
@@ -202,6 +204,9 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
202204
StatisticsStorage storage = new StatisticsStorage();
203205
DevModeUsageStatistics.init(baseDir, storage,
204206
new StatisticsSender(storage));
207+
DevModeUsageStatistics.collectEvent(
208+
"ide_" + OpenInCurrentIde.getIdeAndProcessInfo().ide()
209+
.name().toLowerCase(Locale.ENGLISH));
205210
}
206211

207212
File frontendFolder = config.getFrontendFolder();

0 commit comments

Comments
 (0)