Getting the project location absolute path [message #319133] |
Mon, 13 August 2007 16:52 |
Eclipse User |
|
|
|
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 #319155 is a reply to message #319140] |
Tue, 14 August 2007 08:36 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #319446 is a reply to message #319166] |
Tue, 21 August 2007 14:21 |
Eclipse User |
|
|
|
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 #319471 is a reply to message #319465] |
Wed, 22 August 2007 12:36 |
Eclipse User |
|
|
|
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 #1375779 is a reply to message #1374074] |
Fri, 23 May 2014 06:00 |
prateek gupta 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
|
|
|
Powered by
FUDForum. Page generated in 0.03445 seconds