Re: Getting the absolute path to your plugin in Eclipse... (fwd)


Subject: Re: Getting the absolute path to your plugin in Eclipse... (fwd)
From: Kojarski Sergei (kojarski@ccs.neu.edu)
Date: Wed Nov 13 2002 - 19:27:32 EST


Hi Paul,

> Sergie -
>
> You can get the absolute path to a directory like your plugin directory
> by resolving the URL using the code:
> /**
> * @return Returns the absolute path to this plugin's directory.
> * Returns null if the directory cannot be determined.
> */
> public static String getAbsolutePath(){
> try{
> return
>
> Platform.resolve(plugin.getDescriptor().getInstallURL()).getFile();
> }catch(java.io.IOException e){
> return null;
> }
> }
>

The problem is that this will return you file part of the URL that is not
necessarily on the local user file system. Otherwise they'd use IPath, not
URL.
My solution is to place files from plugin dir in Plagin.startup() to
so-called "plagin state location" - dir inside user workspace dir,
dedicated to store any plug-in information. (We can obtain inputstream to
the plug-in files and put them into store location which is guaranteed to
be on the local file system.)
If it's not local file system I suppose we couldnt use it with aspectj or
java compilers.

> I decided to try something a little different than what I think the rest
> of the class is doing. I didn't want to copy all of the checker files
> to the directory of the project that has enabled the checker. So
> instead I did some digging through the AspectJ plugin api's and have
> found a way to intercept the build call, abort it, and then request a
> new build with my own .lst file.

How? where did you find it?
I think the other solutions is to:
1. Place all the code in some dir and hide this dir from user by applying
a filter (in plugin.xml)

2. Place code in store plugin location on per project basis and just add
it (somehow, but I'm sure it's possible) to project SOURCE classpath entry
or smth like that. It'll be 100% invisible to the user and you don't need
to make your own list files, intercept builder runs etc.

>One nice thing about this is that the
> user is completely blinded to what your plugin is doing, except for the
> fact that LoDChecker class files show up in the users bin (or output)
> directory. This also ensures control over what files are included in
> the compilation.
Yes

> When the user selects a set of of choices off the plugin properties
> page, a unique AnyDynamic file will be created for the project (I
> haven't finalized where I want to place this yet - but probably this
> will go in the user's project directory). When the user then builds his
> project, I intercept the beginning of the build process, abort it, and
> create my own .lst file that has absolute paths to the locations of all
> of the files, and then tell aspectj to build using my .lst file.

> Like I mentioned in the other email, I simply forgot to include the
> org.eclipse.jdt.core library in the list of runtime libraries my plugin
> requires (in the xml file) using:
> <import plugin="org.eclipse.jdt.core"/>

Yes, I didn't even think about it cause I repeated it so many times:
include all the plugins you use in your code into import.....

> Now I can use the core library to modify the class path for the project
> at the time of each build to include the log4j library, and the
> aspectjrt library.
That's what exactly I'm doing with my nice DAJ plugin. + JVM runs... Very
nice. :-)))

Sergei.

> Paul
>
>
> Kojarski Sergei wrote:
>
> >Hi Paul,
> >
> >>I'm not sure, this is not how I approached the problem. Maybe Sergei
> >>can answer this for you. I did not transfer the files, but instead
> >>created a new .lst file and redirected aspectj to use that file. It has
> >>proved to be a bit more difficult though. So I wouldn't recommend
> >>trying to switch now.
> >>
> >
> >What do you mean by "not transferring" files?
> >Can you please tell me more about your approach.
> >
> >(If you just say to AspectJ compiler to use some file from your plugin dir
> >- you have one checker file for all the projects.
> >But since we have GlobalPreffered and Stable properties that can be
> >implemented only by changing source code -> we need to have one
> >checker file per project and one of the ways is to copy checker file into
> >project dir.
> >Secondly, how do you know local file path to any file from your plugin
> >dir? API gives you only URL. Or .lst files may contant URL's?)
> >
> >>I have to use the JavaCore api as well and have just begun to experience
> >>some problems. Our problems are probably similar, I'll let you know if
> >>I figure out how to use it.
> >>
> >
> >It's strange, but at least in my case JavaCore code works fine.
> >
> >>Sergei - Could you give us a hint regarding how to use the JavaCore API.
> >>
> >
> >It seems I already answered this question to Mukta. I suspect it's not
> >necessary to convert files and dirs into java files and packages. It seems
> >to be made implicitly by JDT API on coping... Sorry.
> >
> >Sergei.
> >
> >
> >>Paul
> >>
> >>
> >>Mukta Behere wrote:
> >>
> >>>Hi Paul,
> >>>
> >>>I am using create method of class JavaCore to indicate
> >>>to JDT that I have placed Java source files in the
> >>>project.
> >>>'pack' is the folder 'lawOfDemeter' and 'checker' is
> >>>the 'checker.java' file I copied to the project's
> >>>folder.
> >>>
> >>>Is there any other way to do this ?
> >>>
> >>>Thanks for your help.
> >>>Mukta
> >>>
> >>>
> >>>>Mukta Behere wrote:
> >>>>
> >>>>>Hi Sergei,
> >>>>>
> >>>>>I am trying to call JavaCore.create() and I keep
> >>>>>getting the following error message :
> >>>>>
> >>>>>Unhandled exception caught in event loop.
> >>>>>Reason:
> >>>>>org/eclipse/jdt/core/JavaCore
> >>>>>
> >>>>>I fail to understand why this happens. I checked
> >>>>>
> >>>>the
> >>>>
> >>>>>API - it does not throw any exceptions. Even the
> >>>>>following doesn't work..
> >>>>>
> >>>>>try {
> >>>>> JavaCore.create(pack);
> >>>>> JavaCore.create(checker);
> >>>>>}
> >>>>>catch( Exception e ) {
> >>>>> e.printStackTrace(); // This doesn't work
> >>>>>
> >>>>either?!
> >>>>
> >>>>>}
> >>>>>
> >>>>>Please advise.
> >>>>>
> >>>>>Thanks
> >>>>>-Mukta
> >>>>>
> >>>>>
> >>>>>
> >>>>________________________________________________________________________
> >>>>
> >>>>>Missed your favourite TV serial last night? Try the
> >>>>>
> >>>>new, Yahoo! TV.
> >>>>
> >>>>> visit http://in.tv.yahoo.com
> >>>>>
> >>>>
> >>>________________________________________________________________________
> >>>Missed your favourite TV serial last night? Try the new, Yahoo! TV.
> >>> visit http://in.tv.yahoo.com
> >>>
> >>
> >
> >
>
>



This archive was generated by hypermail 2b28 : Wed Nov 13 2002 - 19:27:34 EST