Eclipse file URL from own bundle - eclipse

this is not really a problem I have, but more a question about good practice.
I want to resolve a URL of a File of my eclipse plugin, but there are many ways which work. I could not find anything about which one should be preferred.
First of all: how should I obtain my bundle? Through the Activator or the Platform?
Bundle bundle = Platform.getBundle("my.bundle.id");
or
Bundle bundle = Activator.getDefault().getBundle();
The other question is how to get the url. Either with
URL url = FileLocator.find(bundle, new Path("folder/file.txt"), null);
or
URL url = bundle.getEntry("folder/file.txt");
All of this works, but which way is the best? Does it even make a difference?

No it doesn't make any difference (actually FileLocator uses bundle.getEntry). The advantage is of using bundle.getEntry is that you don't have a dependency to an eclipse-bundle; I don't know if that fact is relevant for you.
I'm always using the FileLocator method in RCPs but using the openStream method to read the contents of files within bundles.

Related

Access relative path from eclipse-plugin

Does anyone know how to get a file with uri from a self-made Eclipse Plug-in?
Absolute paths would be no problem:
URI.createFileURI("C:/Users/hp/workspace(dke)/SMartGen/StarSchema.profile.uml");
But how do I access local resources relatively?
URI.createFileURI("jar:file:/%ECLIPSE_HOME%/plugins/SMartGen.jar!StarSchema.profile.uml");
doesn't work this way....
Happy for every answer.
lg martin
Use the FileLocator.
Example:
URL iconUrl = FileLocator.find(Platform.getBundle("myBundle"), new Path("icons/someIcon.png"), null);
This will get the URL of a file "someIcon.png" that is located in the "icons" folder in the bundle "myBundle".
For getting a resource out of eclipse, you can use org.osgi.framework.Bundle.getEntry(String). That returns a standard java.net.URL, which can also be used to get the InputStream for consumption. It has the advantage of not caring if your plugin is in directory form, jar form, or in your workspace.
Bundle bundle = FrameworkUtil.getBundle(MyClass.class);
URL url = bundle.getEntry("StarSchema.profile.uml");
URL has a handy toURI() method as well.

Tool to reverse map JSP to URL?

Is there a tool to automate the task of finding out where a given JSP is used, by URL?
Ultimately, the question I need to answer is, What URL(s) do I need to call, to see the output of this JSP in my browser?
Finding out involves searching for the JSP name, then searching for any JSPs that include it (possibly through several levels), ending up with one or more servlets - then trawling through web.xml to get the mapping of URL to servlet.
Having spent this morning doing exactly that, looking for examples of deprecated tags in our project, it seems to me that a computer would be quicker, if not better, at this than I am. For my purposes, I can live with not getting every URL; I really need to see only one use of the file in question.
So, is there a tool to do this? My IDE is Eclipse, so if Eclipse or some plug-in can do this that would be my preferred option. The application is running on Tomcat 6.
Thanks,
Check the contents of web.xml; it contains this mapping.
[EDIT] If you want to remove a JSP, here is what you need to do:
Check for an entry in web.xml
Search for <jsp:include and <%#include in all *.jsp files
That's all the places where your JSP can be used. You don't have to check for redirects and such since for a redirect to work, the JSP must be listed in web.xml.
Why do you require any eclipse plugin?
How about a simple text search in eclipse, where you can do a file search, that is search a text in all required file patterns - as below
(source: dopefly.com)

Launch my app using email attachement

I want to bind my app to some file extension so when I receive an email with an attached file with the correct extension, clicking on it will launch my app and pass it the attached file.
Is it possible ? How ?
Thx
--G.
As iPhone applications are not allowed to share files on the file system, what you're looking for is not immediately possible (not with the published APIs that I know of, anyway). You might still have a couple of options though.
Either way you'll have to use a custom URL scheme, which is associated with your app, and paste that into your email. This URL might point to some external location, which your app can download the file from.
Or it might contain the actual file contents if it's fairly small. URLs are 'just text' (some restrictions apply), so you're free to put any data you want to in it, as long as it is URL-encoded.
You still need to get the URL into the email though, which might or might not be as easy as attaching a file.
It's not possible to simply associate a file extension with an application on the iPhone.
You could create a custom URL scheme that would launch your app, but probably that won't help you.
This is actually possible, I'm working on this exact same problem and this great tutorial has really helped me.

Add files to the app on the run

I was wondering if I could add the files to the app resources from an external url. As in suppose I see a url which has a nice image. Can I download that from the website and add it as a resource and use it locally for later use ? I am sure there is way But Need some guidance on how to approach the problem and The set of Classes that could be used with explanantion.
Thanks,
You can't change anything in your app bundle after it has been signed. If you did, you'd make the signature invalid, and the iPhone would refuse to run your app. Your best bet is to add the files to the Documents or tmp folder. There really isn't much of a reason to have stuff in your own bundle - is there a reason you have to have those images there?

Counting eclipse plugin installations/downloads

I'm currently hosting an Eclipse plugin update site on sourceforge.net . SF.net does not allow access to server logs but I'd still like to know how many downloads the plugin gets.
Is there an alternative way of gathering them?
I'm not going to have any sort of 'call home' feature in the plugin, so please don't suggest that.
I wrote a blog about how to track downloads of an Eclipse plug-in update site. What you can do is specify a url to your server and every time a download is initiated the update site will send an HTTP HEAD request to that url, which you can then use to count the number of times the plug-in was downloaded. If you want to track some information about who is downloading the plug-in you can pass information, like the package name, version, os, and and store it in a database.
http://programmingfortherestofus.blogspot.com/2014/08/tracking-downloads-to-your-eclipse.html
I hope it helps!
It is possible to host the plugin jars in the file release service, and then get your site.xml file to point to them. You need to point at a specific mirror to make it work.
This will tell you how many times people download each file as with a normal file release.
Unfortunately, in practice this is a lot of work to maintain, and tends to be unreliable (I kept getting bug reports saying the update site wasn't working).
You could write a very simple php script which just serves up the relevant file, and logs the download to a file or DB. Make sure it double checks the URL is a valid one to download to the user of course :)
Once that's in place, you can update the site.xml to point to the correct thing, or you could probably use URL rewriting to intercept requests to your jar file and pass them through the script. I've never tried that on the SF servers, but it might work.
EDIT:
Even better, just have a php script which sends a redirect like this:
<?php
$file = $_GET('file');
// Now log the access to file
header('Location: ' . $file);
?>
Just a thought: AFAIK, SourceForge does tell you how much data you served. You know the size of your plugin JARs. Divide the data served by the size of your plugin and you get a rough estimate of how many downloads you had.