简体   繁体   中英

Getting Eclipse project info within an OSGi application

I'm working on a project which inspects Eclipse Java projects and getting some information of source files, using Eclipse AST. Right now it's an Eclipse plugin, but we need to make it independent from Eclipse, we are using only AST libraries of Eclipse.

I've tried copying required JAR's and run the project as a normal Java app(not an Eclipse plugin, not dependent to Eclipse) but then I started getting some errors, because when I run the app outside of Eclipse, AST can't get needed information(project data) from Eclipse and returning null for some cases. For example, when I visit a method invocation( MethodInvocationNode class), I need to know which class's method is this, but I can't because of AST errors I explained( MethodInvocationNode.resolveMethodBinding() returns null in this case).

I think I need to get an IProject , in Eclipse plugin I'm getting that from IWorkspace ( ResourcesPlugin.getWorkspace() ) which I think available in all Eclipse plugins.

Now, I think if I can make an OSGi app of it, maybe I can somehow get that IProject but I have no idea how can I do that. Documentations and tutorials didn't help much. It's also high probability that I'm missing some fundamental points about Eclipse projects and/or OSGi apps :) .

In short, how can I get IProject data within an OSGi app?

First, every Eclipse application is an OSGi-application, so there is no difference in doing things in a pure OSGi environment or Eclipse.

Second the "Workspace" is an Eclipse specific construct, so making your application "independent" from Eclipse makes no sense at all, the contents of a project, especially Java projects are eclipse specific (so you also have to parse the .classpath files with API from Eclipse to know which resources have to be compiled, parse .project files, etc).

The workspace mechanism is part of the bundle org.eclipse.core.resources . You need to include that in your OSGi application. Like already mentioned you can access all things the same way like in an Eclipse environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM