Debugging an eclipse application running programmatically [message #1832649] |
Tue, 22 September 2020 16:48 |
Miroslav Shipilov Messages: 2 Registered: September 2020 |
Junior Member |
|
|
Hello!
I have simple example of my app:
package plugin;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
public class MyActivator implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
for (int i=0 ; i < 10 ; i++) {
Thread.sleep(10000);
System.out.println("MyActivator " + i);
}
return null;
}
@Override
public void stop() {
}
}
In my test I create a startup configuration for this app and launch it, then do all sorts of checks
Example test:
package test;
import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.junit.Test;
public class MyTest {
boolean isStart;
@Test
public void test1() throws CoreException, InterruptedException, IOException {
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type =
manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench");
ILaunchConfigurationWorkingCopy workingCopy =
type.newInstance(null, "Start java");
workingCopy.setAttribute("application","Plugin.MyActovator1");
workingCopy.setAttribute("org.eclipse.jdt.launching.PROGRAM_ARGUMENTS","-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:52245");
workingCopy.setAttribute("org.eclipse.jdt.launching.JRE_CONTAINER","org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8");
workingCopy.setAttribute("product","org.eclipse.platform.ide");
ILaunchConfiguration configuration = workingCopy.doSave();
ILaunch laucnh = configuration.launch(ILaunchManager.DEBUG_MODE, null);
laucnh.getProcesses()[0].getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {
@Override
public void streamAppended(String text, IStreamMonitor monitor) {
System.out.println("APP INFO " + text);
}
});
for (int start = 0; start < 10; start++) {
if (isStart) {
break;
}
Thread.sleep(5000);
}
}
}
The main question is how can I debug the application when running the test since it runs in a separate process? "Remote java application" doesn't help.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03049 seconds