Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325217 - [Linked Resources] Allow creating links to workspace paths
Summary: [Linked Resources] Allow creating links to workspace paths
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Serge Beauchamp CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 336265 (view as bug list)
Depends on: 312760
Blocks:
  Show dependency tree
 
Reported: 2010-09-14 05:51 EDT by James Blackburn CLA
Modified: 2021-09-17 16:31 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2010-09-14 05:51:31 EDT
This may be a duplicate, but I couldn't find it...

It should be possible to create a linked resource relative to the 'dynamic' variable ${workspace_loc:}.  Using paths relative to WORKSPACE_LOC results in simple string concatenation.  This makes it impossible to place projects anywhere on disk, import them, and have links pointing into them work.
Comment 1 Serge Beauchamp CLA 2010-09-14 06:36:07 EDT
Oh, I see the problem.

Instead of having a path relative to the file system location of the workspace, you would like to have a linked resource that resolves the workspace path "/project/dir/", and have the path be based off this?

Right now, there's no such variable provided by default.  

But you can create one yourself, using the core resource variable resolver extension point.

Note that there are some limitations right now, including:

1) it can't use the same syntax as core.variables, since ":" is a path delimiter on some OS, as well as '/'.  So setting the value "${workspace_loc:/foo/bar}" would need to be recorded internally as something like "WORKSPACE_PATH-foo-bar"

2) There's no user-friendly editor to let the user easily build the link resource value, so the user has to enter that clunky format himself at the moment.

Here's what the extension point would should be:

   <extension
         point="org.eclipse.core.resources.variableResolvers">
      <variableResolver
            class="sample.workspace_relative_path.WorkspaceRelativePath"
            variable="WORKSPACE_PATH">
      </variableResolver>
   </extension>

And the implementation:

package sample.workspace_relative_path;

import java.net.URI;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.variableresolvers.PathVariableResolver;
import org.eclipse.core.runtime.Path;

public class WorkspaceRelativePath extends PathVariableResolver {

	public String[] getVariableNames(String variable, IResource resource) {
		return new String[] {"WORKSPACE_PATH"};
	}

	@Override
	public String getValue(String variable, IResource resource) {
		int index = variable.indexOf('-');
		if (index == -1 || index == (variable.length() -1))
			return "";
		
		String argument = variable.substring(index + 1);
		argument = "/" + argument.replace('-', '/');
		IResource target = resource.getWorkspace().getRoot().findMember(Path.fromOSString(argument));
		if (target == null)
			return "";
		URI value = target.getLocationURI();
		if (value == null)
			return null;
		return value.toASCIIString();
	}
Comment 2 Serge Beauchamp CLA 2010-09-14 06:37:54 EDT
bug 312760 is a dependent in order to be able to conveniently edit macros without having to encode values by hand.
Comment 3 James Blackburn CLA 2010-09-14 06:45:37 EDT
Wow, that was fast - thanks Serge!

That's exactly right.  We've extended CDT a fair bit to allow headless project import trees of projects, building them, dumping markers, etc.  See the org.eclipse.cdt.managedbuilder.core.headlessbuild IApplication for it's full functionality.  
Currently the CDT MBS can handle arbitrary project location URIs. So having linked resources which use workspace paths would be really useful where projects aren't directly checked out under the workspace.
Comment 4 James Blackburn CLA 2010-09-14 06:58:07 EDT
Thanks for the example!

It would probably be worth falling back to getFile / getFolder if the path segment lenght > 1 && findMember returns null. This would allow handling resources which may not yet exist or go in and out of existence.

I agree this is a special case of handling arbitrary variables. But it would no doubt be harder / impossible to reference UI dependent variables without stashing the most recent selection.
Comment 5 James Blackburn CLA 2011-02-03 13:06:27 EST
*** Bug 336265 has been marked as a duplicate of this bug. ***
Comment 6 Lars Vogel CLA 2019-09-24 13:57:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 7 Eclipse Genie CLA 2021-09-17 16:31:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.