Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324940

Summary: Listing the projects in the non default workspace actually return the ones in the default workspace
Product: [Eclipse Project] PDE Reporter: Marc Philips <Marc.Philips>
Component: API ToolsAssignee: PDE API Tools Inbox <pde-apitools-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: darin.eclipse, remy.suen
Version: 4.0   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Whiteboard:

Description Marc Philips CLA 2010-09-10 06:01:59 EDT
Build Identifier: 20100617-1415

I am experimenting with plugins and I started eclipse on a different workspace than the one I use for normal developement: in the "Workspace Launcher" window, I selected "/home/phi/rpctraining" rather than "/home/phi/workspace".

Then I wrote some code which, I expected would list the projects defined in the current workspace (thus in "/home/phi/rpctraining"), but I got the ones defined in "/home/phi/workspace" instead.

Reproducible: Always

Steps to Reproduce:
1. Start Eclipse, but select a different workspace than the default one (create one if necessary).

2. Create a new Plug-in Project with an activator.

3. Add org.eclipse.core.resources to the Required Plug-ins (Dependencies tab)

4. Add the following line to the start(BundleContext) method of the activator:

IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project: projects) {
	System.out.println(project);
}

5. Add the required imports to the activator.

6. Run as an OSGi Framework

THe projects listed are the ones from the default workspace.
Comment 1 Remy Suen CLA 2010-09-10 07:20:18 EDT
(In reply to comment #0)
> THe projects listed are the ones from the default workspace.

You mean you want to list the same projects as the Eclipse that you launched your 'OSGi Framework' launch configuration from? I doubt this is possible as your running Eclipse has a lock on that workspace to begin with.
Comment 2 Marc Philips CLA 2010-09-10 08:06:54 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > THe projects listed are the ones from the default workspace.
> You mean you want to list the same projects as the Eclipse that you launched
> your 'OSGi Framework' launch configuration from? I doubt this is possible as
> your running Eclipse has a lock on that workspace to begin with.

Yes, that's what I want to do. But why shouldn't it be possible? I am not launching a new instance of Eclipse, am I? Just running some plug-in code in the context of my current workbench.

Actually, I should have mentionned this in the problem description, but I tried creating the same plugin in a workbench launched with the default workspace ("/home/phi/workspace") and I got the correct result: the listed projects are the ones in the current (default) workspace; so no matter which workspace I launch Eclipse with, I get the project in "/home/phi/workspace".
Comment 3 Remy Suen CLA 2010-09-10 09:08:34 EDT
(In reply to comment #2)
> Yes, that's what I want to do. But why shouldn't it be possible?

Actually, it looks like the workspace locking mechanism is not actually enforced by the org.eclipse.core.resources bundle so it's technically possible to list the projects of a workspace that's currently being "run" by an Eclipse instance.

> I am not
> launching a new instance of Eclipse, am I? Just running some plug-in code in
> the context of my current workbench.

You _are_ launching a separate JVM instance. While you can point it at identical places I wouldn't really argue that it's running in the _same_ context.

> Actually, I should have mentionned this in the problem description, but I tried
> creating the same plugin in a workbench launched with the default workspace
> ("/home/phi/workspace") and I got the correct result: the listed projects are
> the ones in the current (default) workspace; so no matter which workspace I
> launch Eclipse with, I get the project in "/home/phi/workspace".

The destination is dictated by what's returned by Platform.getLocation().
Comment 4 Darin Wright CLA 2010-09-10 09:15:33 EDT
(In reply to comment #2)

> Yes, that's what I want to do. But why shouldn't it be possible? I am not
> launching a new instance of Eclipse, am I? Just running some plug-in code in
> the context of my current workbench.

When you launch OSGi Application or Eclipse Application, you are starting a new runtime with on a different workspace - well, on the workspace specified by your command line args or launch configuration. You are *not* running in the context of your current workbench.
Comment 5 Marc Philips CLA 2010-09-10 09:27:49 EDT
(In reply to comment #0)

Remy, Darin,

Thank you very much for taking the time to explain this to me. Now I understand a bit better what's happening when I run the plugin and I realized how I could achieve the resut I wanted: I simply added "-data ${workspace_loc}" to the program arguments in the Run configuration to ensure that the plugin actually sees the same worksapce than the workbench I am starting it from.

Thanks again ... you guys have a great week-end ;)
Marc