Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Getting the project location absolute path
Getting the project location absolute path [message #319133] Mon, 13 August 2007 16:52 Go to next message
Eclipse UserFriend
Originally posted by: cguibert.axway.com

Hello

Here is my problem: I'm using an Eclipse plug-in using which a user can
select a directory located under its project.
A the time of execution, I have to get this folder (I have a relative
path) and I have to achieve things with the data in the folder.
My problem is that when the project is not located in the workspace, then
I have never able to get the complete absolute path of the folder selected
by the user.
I am able to the workspace location but it is no use because the project
is not in it.
I checked the archives and saw someone (Saman) who had a problem close to
mine. I tried the function getLocationURI, getLocation but each time I
have the location of the workspace, not the one of the project. Finally,
Saman's problem was solved by using a workaround. But I cannot implement
this kind of workaround because the user must select a directory in the
project and this is the only information that is available in my code.

Does anyone have an idea on how I can solve my problem ?

Thanks and regards

CG
Re: Getting the project location absolute path [message #319140 is a reply to message #319133] Mon, 13 August 2007 19:18 Go to previous messageGo to next message
Tanmay Sinha is currently offline Tanmay SinhaFriend
Messages: 11
Registered: July 2009
Junior Member
Hi CG,

Would it be possible for you post the piece of code where you are trying
to achieve this?

I ran into a similar problem for one of my project I might be able to
help if it's the same thing.

-tanmay

CG wrote:
> Hello
>
> Here is my problem: I'm using an Eclipse plug-in using which a user can
> select a directory located under its project.
> A the time of execution, I have to get this folder (I have a relative
> path) and I have to achieve things with the data in the folder.
> My problem is that when the project is not located in the workspace,
> then I have never able to get the complete absolute path of the folder
> selected by the user.
> I am able to the workspace location but it is no use because the project
> is not in it.
> I checked the archives and saw someone (Saman) who had a problem close
> to mine. I tried the function getLocationURI, getLocation but each time
> I have the location of the workspace, not the one of the project.
> Finally, Saman's problem was solved by using a workaround. But I cannot
> implement this kind of workaround because the user must select a
> directory in the project and this is the only information that is
> available in my code.
>
> Does anyone have an idea on how I can solve my problem ?
>
> Thanks and regards
>
> CG
>
Re: Getting the project location absolute path [message #319155 is a reply to message #319140] Tue, 14 August 2007 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cguibert.axway.com

Hi Tanmay

Here is the test code: I tried all the functions that could give me the
proper result byt with no success

IWorkspace myWorkspace = ResourcesPlugin.getWorkspace();
out.println("workspace.fullpath:" + myWorkspace.getRoot().getFullPath());
out.println("workspace.location uri:" +
myWorkspace.getRoot().getLocationURI());
out.println("location: " +
ResourcesPlugin.getWorkspace().getRoot().getLocation());

And here is the resulting file:
workspace.fullpath:/
workspace.location uri:file:/E:/XTP/MyTest/runtime-EclipseApplication
location: E:/XTP/MyTest/runtime-EclipseApplication

My problem is that I have the material property selected by the user that
looks like the following: material
property:/com.axway.xtp.validation.tests/material

And I have to get the full path of the materiel property to access its
content. On my hard drive, I should find a way to get the following:
E:\XTP\MyTest\Tests\xfb_xib\interpel\xtp\com.axway.xtp.conne ctor.tests\material

And as you can, see there is no link between what I am able to read and
what I have to get.

Thanks for your help

Regards

CG
Re: Getting the project location absolute path [message #319165 is a reply to message #319155] Tue, 14 August 2007 12:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

CG,

Have you tried calling these same methods on the IProject instead of the
IWorkspaceRoot?


CG wrote:
> Hi Tanmay
>
> Here is the test code: I tried all the functions that could give me
> the proper result byt with no success
>
> IWorkspace myWorkspace = ResourcesPlugin.getWorkspace();
> out.println("workspace.fullpath:" + myWorkspace.getRoot().getFullPath());
> out.println("workspace.location uri:" +
> myWorkspace.getRoot().getLocationURI());
> out.println("location: " +
> ResourcesPlugin.getWorkspace().getRoot().getLocation());
>
> And here is the resulting file:
> workspace.fullpath:/
> workspace.location uri:file:/E:/XTP/MyTest/runtime-EclipseApplication
> location: E:/XTP/MyTest/runtime-EclipseApplication
>
> My problem is that I have the material property selected by the user
> that looks like the following: material
> property:/com.axway.xtp.validation.tests/material
>
> And I have to get the full path of the materiel property to access
> its content. On my hard drive, I should find a way to get the
> following:
> E:\XTP\MyTest\Tests\xfb_xib\interpel\xtp\com.axway.xtp.conne ctor.tests\material
>
>
> And as you can, see there is no link between what I am able to read
> and what I have to get.
>
> Thanks for your help
>
> Regards
>
> CG
>
>
Re: Getting the project location absolute path [message #319166 is a reply to message #319165] Tue, 14 August 2007 14:45 Go to previous messageGo to next message
Tanmay Sinha is currently offline Tanmay SinhaFriend
Messages: 11
Registered: July 2009
Junior Member
CG,

Ed is right. Look at the following piece of code.


//currentSelection is an IStructuredSelection
IResource currentResource = (IResource)
currentSelection.getFirstElement();
System.out.println("workspace.fullpath:"+ currentResource.getFullPath());
System.out.println("workspace.location uri:"+
currentResource.getLocationURI());
System.out.println("location: " + currentResource.getLocation());

Your code is trying to get the properties of your workspace instead of
the selected resource. The code above gives the correct path on the hard
drive using getLocationURI() and getLocation. GetFullPath() gives you
the relative path from the project root.

Hope that helps.

-tanmay

Ed Merks wrote:
> CG,
>
> Have you tried calling these same methods on the IProject instead of the
> IWorkspaceRoot?
>
>
> CG wrote:
>> Hi Tanmay
>>
>> Here is the test code: I tried all the functions that could give me
>> the proper result byt with no success
>>
>> IWorkspace myWorkspace = ResourcesPlugin.getWorkspace();
>> out.println("workspace.fullpath:" + myWorkspace.getRoot().getFullPath());
>> out.println("workspace.location uri:" +
>> myWorkspace.getRoot().getLocationURI());
>> out.println("location: " +
>> ResourcesPlugin.getWorkspace().getRoot().getLocation());
>>
>> And here is the resulting file:
>> workspace.fullpath:/
>> workspace.location uri:file:/E:/XTP/MyTest/runtime-EclipseApplication
>> location: E:/XTP/MyTest/runtime-EclipseApplication
>>
>> My problem is that I have the material property selected by the user
>> that looks like the following: material
>> property:/com.axway.xtp.validation.tests/material
>>
>> And I have to get the full path of the materiel property to access
>> its content. On my hard drive, I should find a way to get the
>> following:
>> E:\XTP\MyTest\Tests\xfb_xib\interpel\xtp\com.axway.xtp.conne ctor.tests\material
>>
>>
>> And as you can, see there is no link between what I am able to read
>> and what I have to get.
>>
>> Thanks for your help
>>
>> Regards
>>
>> CG
>>
>>
Re: Getting the project location absolute path [message #319446 is a reply to message #319166] Tue, 21 August 2007 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cguibert.axway.com

Dear Ed and Tanmay

Thankd for your answers. However, I don't know how to have get to either
an IProject element or an IStructuredSelection.
I checked the IWorkspace documentation and the ResourcesPlugin
documentation but there is nothing that I can use.
How do you get the reference of the current project ? (remember, this code
is located in an Eclipse plug-in so the name of the project is not known)

Thankd for your answer

Regards

CG
Re: Getting the project location absolute path [message #319465 is a reply to message #319446] Wed, 22 August 2007 02:36 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
CG wrote:
> How do you get the reference of the current project ? (remember, this
> code is located in an Eclipse plug-in so the name of the project is not
> known)

Please define 'current'. How do you dictate which of my N opened
projects is the "current" one.

Regards,
Rem
Re: Getting the project location absolute path [message #319471 is a reply to message #319465] Wed, 22 August 2007 12:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cguibert.axway.com

Hello Rem

I'm using a modified version of the TPTP project (test platform). When you
want to run a test, you have to define first some objects, that are
located in one and only one project.
When you run the test, you specify which test object is to be run. This
object is located in what I called the 'current project'.
So in Eclipsed, when you use the run command, the run function of the
Plugin is called. This is here that I need the physical location of the
project in which the test I started belongs to.
I did a test using the ILaunchConfiguration object but I'm still not able
to get the project.
Do you have any idea ?

Thanks and regards

CG
Re: Getting the project location absolute path [message #1374074 is a reply to message #319471] Thu, 22 May 2014 13:07 Go to previous messageGo to next message
prateek gupta is currently offline prateek guptaFriend
Messages: 2
Registered: May 2014
Junior Member
Hii Please post any solution for the above problem, I am doing a similar project and stuck at same problem.
Re: Getting the project location absolute path [message #1375779 is a reply to message #1374074] Fri, 23 May 2014 06:00 Go to previous message
prateek gupta is currently offline prateek guptaFriend
Messages: 2
Registered: May 2014
Junior Member
I got the answer after some research
//get the current selection in the project explorer
ISelection selection =PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
//get the name of first element in selection part
String name = ((IStructuredSelection)selection).getFirstElement().toString();

/*name consist of very long string but first project name is coming after that \n and than ' '
and sometimes "projectname (not opened)" is coming so i make the split at both to take care*/
try
{
t=name.split("\n");
}catch(Exception e)
{
t=name.split(" ");
}
IProject myWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot().getProject(t[0]);
String s= myWorkspaceRoot.getLocation().toString();

[Updated on: Fri, 23 May 2014 06:02]

Report message to a moderator

Previous Topic:Tried to transfer project from Windows to Linux, lots of "Missing Constraints" now
Next Topic:How to download the text editor source code of java IDE in eclipse?
Goto Forum:
  


Current Time: Fri Apr 26 20:19:52 GMT 2024

Powered by FUDForum. Page generated in 0.03445 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top