Finally, this is how i did it:
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
//Do nothing
}
}, new NullProgressMonitor());
}
This submits job to ResourcePlugin and hence it waits till all resource change related process complete.
To handle the launch/debug process, I get all the launches active and if current project launch is active, I wait for its termination (This has a problem in linux, the isTerminated() function for a launch always return true, even after it is terminated, so I added a timeout while waiting).
To get all launches:
org.eclipse.debug.core.ILaunch launch = DebugPlugin.getDefault().getLaunchManager().getLaunches();
To check if it terminated:
launch.isTerminated();
Source: Eclipse GUI testing is viable