Preference setting to turn on/off TestJars support
This commit is contained in:
@@ -48,7 +48,7 @@ public class BootLaunchActivator extends AbstractUIPlugin {
|
||||
myStore.setValue("cglib.breakpoint.warning.disabled", true);
|
||||
}
|
||||
|
||||
launchManager.addLaunchListener(TestJarLaunchListener.getSingletonInstance());
|
||||
TestJarSupport.start();
|
||||
}
|
||||
|
||||
private void setPreference(String plugin, String key, boolean value) {
|
||||
@@ -74,8 +74,7 @@ public class BootLaunchActivator extends AbstractUIPlugin {
|
||||
if (workspaceListener!=null) {
|
||||
workspaceListener.dispose();
|
||||
}
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
launchManager.removeLaunchListener(TestJarLaunchListener.getSingletonInstance());
|
||||
TestJarSupport.stop();
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,7 @@ import org.springsource.ide.eclipse.commons.livexp.util.Log;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class TestJarLaunchListener implements ILaunchesListener2 {
|
||||
|
||||
private static TestJarLaunchListener instance;
|
||||
class TestJarLaunchListener implements ILaunchesListener2 {
|
||||
|
||||
private static final Pattern TESTJAR_PATTERN = Pattern.compile("^spring-boot-testjars-\\d+\\.\\d+\\.\\d+(.*)?.jar$");
|
||||
|
||||
@@ -54,13 +52,6 @@ public class TestJarLaunchListener implements ILaunchesListener2 {
|
||||
|
||||
public record ExecutableProject(String name, String uri, String gav, String mainClass, Collection<String> classpath) {}
|
||||
|
||||
public static TestJarLaunchListener getSingletonInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TestJarLaunchListener();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void launchRemoved(ILaunch launch) {
|
||||
clearTestJarWorkspaceProjectFiles(launch.getLaunchConfiguration());
|
||||
}
|
||||
@@ -207,4 +198,12 @@ public class TestJarLaunchListener implements ILaunchesListener2 {
|
||||
}
|
||||
}
|
||||
|
||||
void clearTestJarArtifactEnvKeyFromLaunches(ILaunchManager launchManager) {
|
||||
for (ILaunch l : launchManager.getLaunches()) {
|
||||
if (!l.isTerminated() && l.getLaunchConfiguration() != null) {
|
||||
clearTestJarWorkspaceProjectFiles(l.getLaunchConfiguration());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2024 Broadcom, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Broadcom, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.eclipse.boot.launch;
|
||||
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.springframework.ide.eclipse.boot.core.BootActivator;
|
||||
import org.springframework.ide.eclipse.boot.core.BootPreferences;
|
||||
|
||||
public class TestJarSupport {
|
||||
|
||||
private static final TestJarLaunchListener LAUNCHES_LISTENER = new TestJarLaunchListener();
|
||||
|
||||
private static final IPropertyChangeListener PREFERENCE_LISTENER = propertyChange -> {
|
||||
if (BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT.equals(propertyChange.getProperty())) {
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
|
||||
// TestJars support ON
|
||||
launchManager.addLaunchListener(LAUNCHES_LISTENER);
|
||||
} else {
|
||||
// TestJars support OFF
|
||||
launchManager.removeLaunchListener(LAUNCHES_LISTENER);
|
||||
LAUNCHES_LISTENER.clearTestJarArtifactEnvKeyFromLaunches(launchManager);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void start() {
|
||||
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
|
||||
BootActivator.getDefault().getPreferenceStore().addPropertyChangeListener(PREFERENCE_LISTENER);
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
launchManager.addLaunchListener(LAUNCHES_LISTENER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
if (BootActivator.getDefault().getPreferenceStore().getBoolean(BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT)) {
|
||||
BootActivator.getDefault().getPreferenceStore().removePropertyChangeListener(PREFERENCE_LISTENER);
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
launchManager.removeLaunchListener(LAUNCHES_LISTENER);
|
||||
LAUNCHES_LISTENER.clearTestJarArtifactEnvKeyFromLaunches(launchManager);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2015, 2024 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -44,6 +44,9 @@ public class BootPreferences implements IPreferenceChangeListener {
|
||||
public static final String PREF_BOOT_FAST_STARTUP_JVM_ARGS = "org.springframework.ide.eclipse.boot.FastStartupJvmArgs";
|
||||
public static final String BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS = "-XX:TieredStopAtLevel=1";
|
||||
|
||||
public static final String PREF_BOOT_TESTJARS_LAUNCH_SUPPORT = "org.springframework.ide.eclipse.boot.TestJarsLaunch";
|
||||
|
||||
|
||||
// Boot Preference Page ID
|
||||
public static final String BOOT_PREFERENCE_PAGE_ID = "org.springframework.ide.eclipse.boot.ui.preferences.BootPreferencePage";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2023 Pivotal, Inc.
|
||||
* Copyright (c) 2015, 2024 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -15,6 +15,7 @@ import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOO
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_THIN_WRAPPER;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_IGNORE_SILENT_EXIT;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT;
|
||||
|
||||
import org.eclipse.debug.internal.ui.preferences.BooleanFieldEditor2;
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
@@ -71,6 +72,8 @@ public class BootPreferencePage extends FieldEditorPreferencePage implements IWo
|
||||
thinLauncher.setErrorMessage("Thin launcher must be an existing file");
|
||||
setTooltip(thinLauncherComposite, thinLauncher, "Thin boot launcher jar to use in Spring Boot Launch configuration (when that option is enabled in the launch config)");
|
||||
addField(thinLauncher);
|
||||
|
||||
addField(new BooleanFieldEditor2(PREF_BOOT_TESTJARS_LAUNCH_SUPPORT, "TestJars Support", SWT.CHECK, launchGroup));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2024 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -17,6 +17,7 @@ import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOO
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_FAST_STARTUP_JVM_ARGS;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS;
|
||||
import static org.springframework.ide.eclipse.boot.core.BootPreferences.PREF_BOOT_TESTJARS_LAUNCH_SUPPORT;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
@@ -25,7 +26,7 @@ import org.springsource.ide.eclipse.commons.core.preferences.StsProperties;
|
||||
|
||||
/**
|
||||
* Initializer of default values for the Spring Boot support
|
||||
*
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
@@ -34,7 +35,7 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer {
|
||||
@Override
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore store = BootActivator.getDefault().getPreferenceStore();
|
||||
|
||||
|
||||
/*
|
||||
* Note that line below cannot be moved to BootPreferencePage static
|
||||
* init method because the class has BooleanFieldEditor2 import that in
|
||||
@@ -42,13 +43,15 @@ public class PreferencesInitializer extends AbstractPreferenceInitializer {
|
||||
* because workbench may not be started in the case of a unit test
|
||||
*/
|
||||
store.setDefault(PREF_IGNORE_SILENT_EXIT, DEFAULT_PREF_IGNORE_SILENT_EXIT);
|
||||
|
||||
|
||||
store.setDefault(PREF_INITIALIZR_URL, StsProperties.getInstance().get("spring.initializr.json.url"));
|
||||
|
||||
|
||||
store.setDefault(PREF_BOOT_FAST_STARTUP_DEFAULT, true);
|
||||
store.setDefault(PREF_BOOT_FAST_STARTUP_REMIND_MESSAGE, true);
|
||||
store.setDefault(PREF_BOOT_FAST_STARTUP_JVM_ARGS, BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS);
|
||||
store.setDefault(BOOT_FAST_STARTUP_DEFAULT_JVM_ARGS, DEFAULT_PREF_IGNORE_SILENT_EXIT);
|
||||
store.setDefault(PREF_BOOT_TESTJARS_LAUNCH_SUPPORT, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user