boolean connectInDebugMode(ILaunch launch, IServer iServer, IProgressMonitor monitor)
throws CoreException {
this.launch = launch;
boolean success = false;
IVMConnector connector = null;
connector = JavaRuntime.getVMConnector("org.eclipse.jdt.launching.socketAttachConnector");
if (connector == null) {
connector = JavaRuntime.getDefaultVMConnector();
}
if (connector == null) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst",
"Could not get jvm connctor"));
}
ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) iServer.loadAdapter(SlingLaunchpadServer.class,
monitor);
ISlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
int debugPort = configuration.getDebugPort();
if (debugPort<=0) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst",
"debug port not configured"));
}
Map<String, String> connectMap = new HashMap<String, String>();
connectMap.put("hostname", iServer.getHost());
connectMap.put("port", String.valueOf(debugPort));
// Map argMap = null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map)null);
int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
connectMap.put("timeout", Integer.toString(connectTimeout)); //$NON-NLS-1$
// set the default source locator if required
@SuppressWarnings("restriction")
ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
sourceLocator
.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager()
.getSourcePathComputer(
"org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer")); //$NON-NLS-1$
List<ISourceContainer> l = new LinkedList<ISourceContainer>();
IJavaProject[] javaProjects = ProjectHelper.getAllJavaProjects();
if (javaProjects!=null) {
for (int i = 0; i < javaProjects.length; i++) {
IJavaProject javaProject = javaProjects[i];
JavaProjectSourceContainer sc = new JavaProjectSourceContainer(javaProject);
l.add(sc);
// ISourceContainer[] scs = sc.getSourceContainers();
// if (scs!=null && scs.length>0) {
// for (int j = 0; j < scs.length; j++) {
// ISourceContainer iSourceContainer = scs[j];
// l.add(iSourceContainer);
// }
// } else {
// }
}
ISourceContainer[] containers = l.toArray(new ISourceContainer[l.size()]);
sourceLocator.setSourceContainers(containers);
sourceLocator.initializeParticipants();
// sourceLocator.initializeDefaults(configuration);
launch.setSourceLocator(sourceLocator);
}
// setDefaultSourceLocator(getServer().getLaunch(), null);
monitor.worked(1);
// connect to remote VM
try{
connector.connect(connectMap, monitor, launch);
success = true;
} catch(Exception e) {
throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst",
"could not establish debug connection to "+iServer.getHost()+" : "+debugPort, e));
}