0

I am developing an Ant task that runs inside an Eclipse workbench.

The Ant task needs to complete a simple mission: closing and reopening a project.

However, the following code:

IProject project = ...;
project.close(null);
project.open(null);

Doesn't seem to have exactly the same outcome as closing a project and re-opening it using the UI.

It seems to me that the UI operation of "opening a project" consists of more than just calling project.open(); something along the the lines of calling plugins that "respond" to the project's open() call.

Is there a convenient way to imitate Eclipse's UI functionality of opening a project? I reckon that this code has to be encapsulated somewhere, but looking through Eclipse's vast source code doesn't seem to reveal much.

EDIT background:

I am actually using Rational Application Developer (v9). I am using the projectSetImport Ant task to import existing projects from the filesystem into the workbench. These projects are a part of Git repository. What I noticed is that, once the projects are imported into the workspace, the EGit functionality isn't available on these projects unless I close the projects and reopen them (through the UI).

Isaac
  • 16,458
  • 5
  • 57
  • 81
  • What do you mean by imitate Eclipse's UI functionality? project.open() fires ResourceChangeEvents to which interested listeners respond. If you want the referenced projects to be opened as well, look at org.eclipse.ui.actions.OpenResourceAction – Sasikanth Bharadwaj Aug 06 '14 at 08:40
  • Why do you want to close and then open? There may be a better way of doing whatever it is you are trying to achieve. – greg-449 Aug 06 '14 at 08:51
  • @greg-449 I updated my question accordingly. Hope it's clear... – Isaac Aug 06 '14 at 16:15

1 Answers1

1

The Project Open GUI code does not do much more than call IProject.open, it does use a progress monitor and an IWorkspaceRunnable - which will change the way resource change events are generated slightly.

The code is org.eclipse.jdt.ui.actions.OpenProjectAction - particularly the internalRun method.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Hmmmm. Indeed. I already tried something along the lines of what's written there, but it didn't work. I guess the problem is elsewhere, then. Still, you answered the question so I'm going to accept it. – Isaac Aug 06 '14 at 16:55