Skip to content

Commit d3af0a3

Browse files
committed
Preference setting to turn on/off TestJars support
1 parent 1b148de commit d3af0a3

File tree

10 files changed

+231
-112
lines changed

10 files changed

+231
-112
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchActivator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void start(BundleContext context) throws Exception {
4848
myStore.setValue("cglib.breakpoint.warning.disabled", true);
4949
}
5050

51-
launchManager.addLaunchListener(TestJarLaunchListener.getSingletonInstance());
51+
TestJarSupport.start();
5252
}
5353

5454
private void setPreference(String plugin, String key, boolean value) {
@@ -74,8 +74,7 @@ public void stop(BundleContext context) throws Exception {
7474
if (workspaceListener!=null) {
7575
workspaceListener.dispose();
7676
}
77-
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
78-
launchManager.removeLaunchListener(TestJarLaunchListener.getSingletonInstance());
77+
TestJarSupport.stop();
7978
super.stop(context);
8079
}
8180

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/TestJarLaunchListener.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,14 @@
4444
import com.google.gson.reflect.TypeToken;
4545

4646
@SuppressWarnings("restriction")
47-
public class TestJarLaunchListener implements ILaunchesListener2 {
48-
49-
private static TestJarLaunchListener instance;
47+
class TestJarLaunchListener implements ILaunchesListener2 {
5048

5149
private static final Pattern TESTJAR_PATTERN = Pattern.compile("^spring-boot-testjars-\\d+\\.\\d+\\.\\d+(.*)?.jar$");
5250

5351
private static final String TESTJAR_ARTIFACTS = "spring.boot.test-jar-artifacts";
5452

5553
public record ExecutableProject(String name, String uri, String gav, String mainClass, Collection<String> classpath) {}
5654

57-
public static TestJarLaunchListener getSingletonInstance() {
58-
if (instance == null) {
59-
instance = new TestJarLaunchListener();
60-
}
61-
return instance;
62-
}
63-
6455
public void launchRemoved(ILaunch launch) {
6556
clearTestJarWorkspaceProjectFiles(launch.getLaunchConfiguration());
6657
}
@@ -207,4 +198,12 @@ public void launchesTerminated(ILaunch[] launches) {
207198
}
208199
}
209200

201+
void clearTestJarArtifactEnvKeyFromLaunches(ILaunchManager launchManager) {
202+
for (ILaunch l : launchManager.getLaunches()) {
203+
if (!l.isTerminated() && l.getLaunchConfiguration() != null) {
204+
clearTestJarWorkspaceProjectFiles(l.getLaunchConfiguration());
205+
}
206+
}
207+
}
208+
210209
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.eclipse.boot.launch;
12+
13+
import org.eclipse.debug.core.DebugPlugin;
14+
import org.eclipse.debug.core.ILaunchManager;
15+
import org.eclipse.jface.util.IPropertyChangeListener;
16+
import org.springframework.ide.eclipse.boot.core.BootActivator;
17+
import org.springframework.ide.eclipse.boot.core.BootPreferences;
18+
19+
public class TestJarSupport {
20+
21+
private static final TestJarLaunchListener LAUNCHES_LISTENER = new TestJarLaunchListener();
22+
23+
private static final IPropertyChangeListener PREFERENCE_LISTENER = propertyChange -> {
24+
if (BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT.equals(propertyChange.getProperty())) {
25+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
26+
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
27+
// TestJars support ON
28+
launchManager.addLaunchListener(LAUNCHES_LISTENER);
29+
} else {
30+
// TestJars support OFF
31+
launchManager.removeLaunchListener(LAUNCHES_LISTENER);
32+
LAUNCHES_LISTENER.clearTestJarArtifactEnvKeyFromLaunches(launchManager);
33+
}
34+
}
35+
};
36+
37+
public static void start() {
38+
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
39+
BootActivator.getDefault().getPreferenceStore().addPropertyChangeListener(PREFERENCE_LISTENER);
40+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
41+
launchManager.addLaunchListener(LAUNCHES_LISTENER);
42+
}
43+
44+
}
45+
46+
public static void stop() {
47+
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
48+
BootActivator.getDefault().getPreferenceStore().removePropertyChangeListener(PREFERENCE_LISTENER);
49+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
50+
launchManager.removeLaunchListener(LAUNCHES_LISTENER);
51+
LAUNCHES_LISTENER.clearTestJarArtifactEnvKeyFromLaunches(launchManager);
52+
}
53+
}
54+
55+
}

eclipse-extensions/org.springframework.ide.eclipse.boot/src/org/springframework/ide/eclipse/boot/core/BootPreferences.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2017 Pivotal, Inc.
2+
* Copyright (c) 2015, 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,6 +44,9 @@ public class BootPreferences implements IPreferenceChangeListener {
4444
public static final String PREF_BOOT_FAST_STARTUP_JVM_ARGS = "org.springframework.ide.eclipse.boot.FastStartupJvmArgs";
4545
public static final String BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS = "-XX:TieredStopAtLevel=1";
4646

47+
public static final String PREF_BOOT_TESTJARS_LAUNCH_SUPPORT = "org.springframework.ide.eclipse.boot.TestJarsLaunch";
48+
49+
4750
// Boot Preference Page ID
4851
public static final String BOOT_PREFERENCE_PAGE_ID = "org.springframework.ide.eclipse.boot.ui.preferences.BootPreferencePage";
4952

eclipse-extensions/org.springframework.ide.eclipse.boot/src/org/springframework/ide/eclipse/boot/ui/preferences/BootPreferencePage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2023 Pivotal, Inc.
2+
* Copyright (c) 2015, 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
@@ -15,6 +15,7 @@
1515
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE;
1616
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_THIN_WRAPPER;
1717
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_IGNORE_SILENT_EXIT;
18+
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT;
1819

1920
import org.eclipse.debug.internal.ui.preferences.BooleanFieldEditor2;
2021
import org.eclipse.jface.layout.GridDataFactory;
@@ -71,6 +72,8 @@ protected void createFieldEditors() {
7172
thinLauncher.setErrorMessage("Thin launcher must be an existing file");
7273
setTooltip(thinLauncherComposite, thinLauncher, "Thin boot launcher jar to use in Spring Boot Launch configuration (when that option is enabled in the launch config)");
7374
addField(thinLauncher);
75+
76+
addField(new BooleanFieldEditor2(PREF_BOOT_TESTJARS_LAUNCH_SUPPORT, "TestJars Support", SWT.CHECK, launchGroup));
7477
}
7578

7679

eclipse-extensions/org.springframework.ide.eclipse.boot/src/org/springframework/ide/eclipse/boot/ui/preferences/PreferencesInitializer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 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
@@ -17,6 +17,7 @@
1717
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE;
1818
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_JVM_ARGS;
1919
import static org.springframework.ide.eclipse.boot.core.BootPreferences.BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS;
20+
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT;
2021

2122
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
2223
import org.eclipse.jface.preference.IPreferenceStore;
@@ -25,7 +26,7 @@
2526

2627
/**
2728
* Initializer of default values for the Spring Boot support
28-
*
29+
*
2930
* @author Alex Boyko
3031
*
3132
*/
@@ -34,21 +35,23 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer {
3435
@Override
3536
public void initializeDefaultPreferences() {
3637
IPreferenceStore store = BootActivator.getDefault().getPreferenceStore();
37-
38+
3839
/*
3940
* Note that line below cannot be moved to BootPreferencePage static
4041
* init method because the class has BooleanFieldEditor2 import that in
4142
* turn activate eclipse preferences debug plugin which throws exception
4243
* because workbench may not be started in the case of a unit test
4344
*/
4445
store.setDefault(PREF_IGNORE_SILENT_EXIT, DEFAULT_PREF_IGNORE_SILENT_EXIT);
45-
46+
4647
store.setDefault(PREF_INITIALIZR_URL, StsProperties.getInstance().get("spring.initializr.json.url"));
47-
48+
4849
store.setDefault(PREF_BOOT_FAST_STARTUP_DEFAULT, true);
4950
store.setDefault(PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE, true);
5051
store.setDefault(PREF_BOOT_FAST_STARTUP_JVM_ARGS, BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS);
52+
store.setDefault(BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS, DEFAULT_PREF_IGNORE_SILENT_EXIT);
53+
store.setDefault(PREF_BOOT_TESTJARS_LAUNCH_SUPPORT, true);
5154
}
52-
55+
5356

5457
}

vscode-extensions/vscode-spring-boot/lib/Main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ExtensionAPI } from "./api";
1919
import {registerClasspathService} from "@pivotal-tools/commons-vscode/lib/classpath";
2020
import {registerJavaDataService} from "@pivotal-tools/commons-vscode/lib/java-data";
2121
import * as setLogLevelUi from './set-log-levels-ui';
22+
import { startTestJarSupport } from "./test-jar-launch";
2223

2324
const PROPERTIES_LANGUAGE_ID = "spring-boot-properties";
2425
const YAML_LANGUAGE_ID = "spring-boot-properties-yaml";
@@ -137,6 +138,9 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
137138
highlightCodeLensSettingKey: 'boot-java.highlight-codelens.on'
138139
};
139140

141+
// Register launch config contributior to java debug launch to be able to connect to JMX
142+
context.subscriptions.push(startDebugSupport());
143+
140144
return commons.activate(options, context).then(client => {
141145
commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
142146
// Boot LS is fully started
@@ -146,8 +150,9 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
146150
// Force classpath listener to be enabled. Boot LS can only be launched iff classpath is available and there Spring-Boot on the classpath somewhere.
147151
commands.executeCommand('sts.vscode-spring-boot.enableClasspathListening', true);
148152

149-
// Register launch config contributior to java debug launch to be able to connect to JMX
150-
context.subscriptions.push(startDebugSupport());
153+
// Register TestJars launch support
154+
context.subscriptions.push(startTestJarSupport());
155+
151156
}));
152157
commands.registerCommand('vscode-spring-boot.ls.stop', () => client.stop());
153158
liveHoverUi.activate(client, options, context);

0 commit comments

Comments
 (0)