Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » how to get path for files in the plugin?
how to get path for files in the plugin? [message #38480] Wed, 10 June 2009 02:42 Go to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Does anyone have reusable code to get the full path name of files from my
plugin to be able to test with? (Could be different depending on what
machine and workspace my code is deployed on). Thanks!

-Steve
Re: how to get path for files in the plugin? [message #38580 is a reply to message #38480] Wed, 10 June 2009 06:25 Go to previous messageGo to next message
Stefan Seelmann is currently offline Stefan SeelmannFriend
Messages: 11
Registered: July 2009
Junior Member
Hi Steve,

You could get the path to the working directory using:
org.eclipse.core.runtime.Platform.getInstanceLocation().getU RL()

Kind Regards,
Stefan


Steven Chamberlin wrote:
> Does anyone have reusable code to get the full path name of files from
> my plugin to be able to test with? (Could be different depending on what
> machine and workspace my code is deployed on). Thanks!
>
> -Steve
>
Re: how to get path for files in the plugin? [message #38613 is a reply to message #38580] Wed, 10 June 2009 06:58 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Thanks Stefan

I tried this and what I get is the path to the junit-workspace. What I'd
actually like is the path to the root of my development workspace. I want
this because the Eclipse application that I am testing has an import
function that I want to test with some files that I want to keep packaged
with my source code so that everything can be checked out together from
the source code repository (if that makes sense).

I tried this code:

URL url = new URL(Activator.getDefault().getBundle().getEntry("/"),
"data/script.sql");
System.out.println("url.getpath is returning: " + url.getPath());

but it printed out a relative path:
url.getpath is returning: /data/script.sql

I want it to print out the full path ... Any idea?

Thanks a lot,

Steve
Re: how to get path for files in the plugin? [message #38683 is a reply to message #38613] Wed, 10 June 2009 07:29 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
I should clarify, when I say "development workspace", I mean, the
workspace where I am developing the SWT-Bot tests and I keep my .java
files with SWT-Bot code ...
Re: how to get path for files in the plugin? [message #38738 is a reply to message #38480] Wed, 10 June 2009 08:35 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 10/6/09 08:12, Steven Chamberlin wrote:
> Does anyone have reusable code to get the full path name of files from
> my plugin to be able to test with? (Could be different depending on what
> machine and workspace my code is deployed on). Thanks!
>
> -Steve
>

Platform.getBundle("com.foo.bar").getEntry("/icons/my.png ")

Gets you the file "/icons/my.png" from the com.foo.bar bundle.

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Re: how to get path for files in the plugin? [message #38836 is a reply to message #38613] Wed, 10 June 2009 23:05 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan PatelFriend
Messages: 68
Registered: July 2009
Member
You are on the right track. The URL you got should have the file you
need. You can use the toURI().toFile() method to convert it to File
object. This might not work if your plugin is installed as jar file...so
better way might be to use the openStream() method and copy the content to
temp file if you need the File itself.
Re: how to get path for files in the plugin? [message #38867 is a reply to message #38836] Wed, 10 June 2009 23:18 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan PatelFriend
Messages: 68
Registered: July 2009
Member
You can also use following helper class depending on if your application
has OSGi...org.eclipse.core.runtime.FileLocator.toFileURL(URL)
Re: how to get path for files in the plugin? [message #808137 is a reply to message #38867] Mon, 27 February 2012 12:50 Go to previous messageGo to next message
Roopa V is currently offline Roopa VFriend
Messages: 4
Registered: February 2012
Junior Member
Even I am trying to achieve a similar result but could not get through the errors to try this code.

I am trying to access the test files in my working directory during runtime. I used similar code as in the post but I get the following errors.

Code snippet
*********************************************************************************

@Test
public void setup1() throws Exception{
URL url = new URL(Activator.getDefault().getBundle().getEntry("/"),
"testdata/main.aql");
}
******************************************************************************

I am new to eclipse and SWTBot. Can you please let me know how to resolve these errors?

Multiple markers at this line
- The method getBundle() is undefined for the type Activator
- Discouraged access: The method getDefault() from the type Activator is not accessible due to restriction on required library C:\eclipse\plugins
\org.eclipse.core.contenttype_3.4.100.v20100505-1235.jar
- Discouraged access: The type Activator is not accessible due to restriction on required library C:\eclipse\plugins
\org.eclipse.core.contenttype_3.4.100.v20100505-1235.jar
Re: how to get path for files in the plugin? [message #809912 is a reply to message #808137] Wed, 29 February 2012 12:35 Go to previous message
Roopa V is currently offline Roopa VFriend
Messages: 4
Registered: February 2012
Junior Member
Atlast I got it working as i just need the absolute path of a file with following line

System.out.print(new File("testdata/textanalytics/test_files/src/main.aql").getAbsolutePath());

Please note that when you use the relative file path do not start with a '/'.

Previous Topic:Pop up shell with dynamic Title text
Next Topic:Discouraged access: for the method getDefault()
Goto Forum:
  


Current Time: Thu Nov 14 07:50:25 GMT 2024

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

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

Back to the top