Skip to main content



      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] Tue, 09 June 2009 22:42 Go to next message
Eclipse UserFriend
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 02:25 Go to previous messageGo to next message
Eclipse UserFriend
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 02:58 Go to previous messageGo to next message
Eclipse UserFriend
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 03:29 Go to previous messageGo to next message
Eclipse UserFriend
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 04:35 Go to previous messageGo to next message
Eclipse UserFriend
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 19:05 Go to previous messageGo to next message
Eclipse UserFriend
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 19:18 Go to previous messageGo to next message
Eclipse UserFriend
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 07:50 Go to previous messageGo to next message
Eclipse UserFriend
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 07:35 Go to previous message
Eclipse UserFriend
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: Fri Apr 18 13:00:13 EDT 2025

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

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

Back to the top