Subject: Getting the absolute path to your plugin in Eclipse...
From: Paul Freeman (pfreeman@ccs.neu.edu)
Date: Wed Nov 13 2002 - 18:53:17 EST
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;
}
}
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. 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.
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"/>
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.
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 - 18:56:20 EST