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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user