Commit 3d37440c authored by Romain Bioteau's avatar Romain Bioteau

fix(h2Console) close previous console

Closes BS-18946
parent dbde43c1
......@@ -31,6 +31,7 @@ import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
......@@ -65,6 +66,9 @@ public class OpenH2ConsoleHandlerTest {
@Mock
private ILaunchConfigurationWorkingCopy workingCopy;
@Mock
private ILaunch launch;
@Before
public void setUp() throws Exception {
doReturn("/test/h2_db").when(openH2ConsoleHandler).pathToDBFolder(repositoryAccessor);
......@@ -74,6 +78,7 @@ public class OpenH2ConsoleHandlerTest {
when(launchManager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE))
.thenReturn(lanchConfigurationType);
when(lanchConfigurationType.newInstance(any(IContainer.class), notNull(String.class))).thenReturn(workingCopy);
when(workingCopy.launch(ILaunchManager.RUN_MODE, Repository.NULL_PROGRESS_MONITOR)).thenReturn(launch);
}
@Test
......
......@@ -31,10 +31,13 @@ import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.jdt.internal.launching.StandardVMType;
......@@ -49,9 +52,17 @@ public class OpenH2ConsoleHandler {
private static final String DRIVER = "org.h2.Driver";
private static final String USER = "sa";
private static final int PORT = SocketUtil.findFreePort();
private IProcess currentProcess;
@Execute
public void execute(final RepositoryAccessor repositoryAccessor) {
if (currentProcess != null) {
try {
currentProcess.terminate();
} catch (DebugException e) {
BonitaStudioLog.error(e);
}
}
final ILaunchManager manager = getLaunchManager();
final ILaunchConfigurationType ltype = manager
.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
......@@ -62,7 +73,11 @@ public class OpenH2ConsoleHandler {
Joiner.on(" ").join(buildCommand(repositoryAccessor)));
workingCopy.setAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, true);
workingCopy.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, logFile().getAbsolutePath());
workingCopy.launch("run", Repository.NULL_PROGRESS_MONITOR);
ILaunch launch = workingCopy.launch(ILaunchManager.RUN_MODE, Repository.NULL_PROGRESS_MONITOR);
IProcess[] processes = launch.getProcesses();
if (processes != null && processes.length == 1) {
currentProcess = processes[0];
}
} catch (final CoreException | IOException e) {
BonitaStudioLog.error("Failed to run h2 console", e);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment