Skip to content

Commit 8349671

Browse files
committed
Preference to enable/disable regeneration of Modulith metadata
1 parent 0e7fe79 commit 8349671

File tree

7 files changed

+57
-13
lines changed

7 files changed

+57
-13
lines changed

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -44,4 +44,6 @@ public class Constants {
4444
public static final String PREF_START_LS_EARLY = "start.boot-ls.early";
4545

4646
public static final String PREF_COMMON_PROPS_METADATA = "boot-java.common.properties-metadata";
47+
48+
public static final String PREF_MODULITH = "boot-java.modulith-project-tracking";
4749
}

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -212,6 +212,7 @@ private void sendConfiguration() {
212212
bootJavaObj.put("change-detection", bootChangeDetection);
213213
bootJavaObj.put("validation", validation);
214214
bootJavaObj.put("remote-apps", getAllRemoteApps());
215+
bootJavaObj.put("modulith-project-tracking", preferenceStore.getBoolean(Constants.PREF_MODULITH));
215216

216217
bootJavaObj.put("rewrite", Map.of(
217218
"recipe-filters", StringListEditor.decode(preferenceStore.getString(Constants.PREF_REWRITE_RECIPE_FILTERS)),

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/prefs/BootJavaPreferencesPage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -42,6 +42,9 @@ protected void createFieldEditors() {
4242
addField(new BooleanFieldEditor(Constants.PREF_SCAN_JAVA_TEST_SOURCES, "Scan Java test sources", fieldEditorParent));
4343

4444
addField(new BooleanFieldEditor(Constants.PREF_CHANGE_DETECTION, "Live Boot Change Detection", fieldEditorParent));
45+
46+
// Experimental Modulith support
47+
addField(new BooleanFieldEditor(Constants.PREF_MODULITH, "Spring Boot Modulith automatic project tracking and metadata update", fieldEditorParent));
4548

4649
Composite c = new Composite(fieldEditorParent, SWT.NONE);
4750
GridDataFactory.fillDefaults().grab(true, false).applyTo(c);

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/prefs/PrefsInitializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void initializeDefaultPreferences() {
6060
"org.springframework.rewrite.test.*",
6161
"rewrite.test.*"
6262
}));
63+
64+
preferenceStore.setDefault(Constants.PREF_MODULITH, true);
6365
}
6466

6567
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2023 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -91,6 +91,11 @@ public boolean isScanJavaTestSourcesEnabled() {
9191
return enabled != null && enabled.booleanValue();
9292
}
9393

94+
public boolean isModulithAutoProjectTrackingEnabled() {
95+
Boolean enabled = settings.getBoolean("boot-java", "modulith-project-tracking");
96+
return enabled != null && enabled.booleanValue();
97+
}
98+
9499
public String[] xmlBeansFoldersToScan() {
95100
String foldersStr = settings.getString("boot-java", "support-spring-xml-config", "scan-folders");
96101
if (foldersStr != null) {

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/modulith/ModulithService.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ public class ModulithService {
7676
private static final String CMD_LIST_MODULITH_PROJECTS = "sts/modulith/projects";
7777

7878
private final ExecutorService executor;
79+
private final ProjectObserver.Listener projectListener;
80+
private final ProjectObserver projectObserver;
81+
private final JavaProjectFinder projectFinder;
7982

8083
private SimpleLanguageServer server;
8184
private SpringSymbolIndex springIndex;
8285
private BootJavaReconcileEngine reconciler;
8386
private BootJavaConfig config;
87+
private boolean autoTrackingProjects;
8488

8589
private Map<URI, AppModules> cache;
8690
private Map<URI, CompletableFuture<Boolean>> metadataRequested;
@@ -94,6 +98,8 @@ public ModulithService(
9498
BootJavaReconcileEngine reconciler,
9599
BootJavaConfig config
96100
) {
101+
this.projectFinder = projectFinder;
102+
this.projectObserver = projectObserver;
97103
this.config = config;
98104
this.cache = new ConcurrentHashMap<>();
99105
this.metadataRequested = new ConcurrentHashMap<>();
@@ -102,8 +108,9 @@ public ModulithService(
102108
this.springIndex = springIndex;
103109
this.reconciler = reconciler;
104110
this.executor = Executors.newCachedThreadPool();
111+
this.autoTrackingProjects = false;
105112

106-
projectObserver.addListener(new ProjectObserver.Listener() {
113+
this.projectListener = new ProjectObserver.Listener() {
107114

108115
@Override
109116
public void deleted(IJavaProject project) {
@@ -113,13 +120,7 @@ public void deleted(IJavaProject project) {
113120

114121
@Override
115122
public void created(IJavaProject project) {
116-
if (isModulithDependentProject(project)) {
117-
if (anyClassFilesPresent(project)) {
118-
requestMetadata(project, DEBOUNCE_TIME).thenAccept(res -> startListening(project));
119-
} else {
120-
startListening(project);
121-
}
122-
}
123+
projectAdded(project);
123124
}
124125

125126
@Override
@@ -135,7 +136,7 @@ public void changed(IJavaProject project) {
135136
}
136137
}
137138
}
138-
});
139+
};
139140

140141
server.onCommand(CMD_MODULITH_REFRESH, params -> {
141142
String uri = ((JsonElement) params.getArguments().get(0)).getAsString();
@@ -150,6 +151,31 @@ public void changed(IJavaProject project) {
150151
);
151152
});
152153

154+
config.addListener(v -> setAutoTrackingProjects(config.isModulithAutoProjectTrackingEnabled()));
155+
156+
}
157+
158+
private void projectAdded(IJavaProject project) {
159+
if (isModulithDependentProject(project)) {
160+
if (anyClassFilesPresent(project)) {
161+
requestMetadata(project, DEBOUNCE_TIME).thenAccept(res -> startListening(project));
162+
} else {
163+
startListening(project);
164+
}
165+
}
166+
}
167+
168+
private void setAutoTrackingProjects(boolean autoTrackingProjects) {
169+
if (this.autoTrackingProjects != autoTrackingProjects) {
170+
this.autoTrackingProjects = autoTrackingProjects;
171+
if (autoTrackingProjects) {
172+
projectObserver.addListener(projectListener);
173+
projectFinder.all().forEach(this::projectAdded);
174+
} else {
175+
projectObserver.removeListener(projectListener);
176+
projectFinder.all().forEach(this::stopListening);
177+
}
178+
}
153179
}
154180

155181
private boolean startListening(IJavaProject project) {

vscode-extensions/vscode-spring-boot/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@
229229
},
230230
"description": "Array of jmx urls pointing to remote spring boot applications to poll for live hover information. A typical url looks something like this: `service:jmx:rmi://localhost:9111/jndi/rmi://localhost:9111/jmxrmi`"
231231
},
232+
"boot-java.modulith-project-tracking": {
233+
"type": "boolean",
234+
"default": true,
235+
"description": "Spring Boot Modulith automatic project tracking and metadata update"
236+
},
232237
"boot-java-vscode-only.test-jars": {
233238
"type": "boolean",
234239
"default": true,

0 commit comments

Comments
 (0)