Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: Re: [cdt-dev] Using the CDT API from a Java application, rather than an Eclipse Plugin

Title: Samsung Enterprise Portal mySingle

Hello,

I too was trying to use CodanApplication from a normal Java Application the same way Marica M was doing and getting the same exception. So, I had to use headlessbuild application to import the source (into a default workspace created in user directory) like this-

 

Process proc = Runtime.getRuntime().exec( "eclipsec -clean -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import " + projectPath);

 

and after that use CodanApplication to do static analysis of the source, like this-

Process proc2 = Runtime.getRuntime().exec("eclipsec -clean -nosplash -application org.eclipse.cdt.codan.core.CodanApplication -verbose " + projectName);

 

CodanApplication looks for the projectName in the default workspace and starts analysis.

 

One doubt, that I have, is to run the headlessbuild and CodanApplication, do I really need complete eclipse intallation or is there any way to use only minimal componenets of the platform. Plz suggest.

 

Sanjay Gupta

 

 



Yes, this is the purpose behind breaking out core and UI to separate plug-ins, to allow them to be used headlessly, or using an alternate UI (like a Web UI maybe ;). But as James mentioned, they are not intended to be used outside of the Eclipse Platform (despite what one group has done ;). If this is too resource heavy, we should be looking at ways to make the platform more light weight when run headless.

:D

On Fri, May 7, 2010 at 6:56 AM, James Blackburn <jamesblackburn@xxxxxxxxx> wrote:
On 7 May 2010 11:52, Marica M <marica.marius@xxxxxxxxx> wrote:
> I'm trying to use the CDT API from an ordinary Java application, and not
> from an Eclipse plug-in.
>
> Generally speaking, is that possible?

Make it an Eclipse IApplication. CDT depends on other platform plugins
such as core.resources, and the runtime core.jobs. You'll still need
OSGI and the platform plugins, but this will allow you to use the core
features headlessly.

James

>
>
> When I try to run the below program, I get an exception regarding a "closed
> workspace".
> Is there another way for getting the AST, that doesn't involve Eclipse?
>
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at JavaApp.main(InstrumentMe.java:18)
> Caused by: java.lang.IllegalStateException: Workspace is closed.
> at
> org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java
> :340)
> at org.eclipse.cdt.internal.core.model.CModel.<init>(CModel.java:37)
> at
> org.eclipse.cdt.internal.core.model.CModelManager.<init>(CModelManager.java:
> 90)
> at
> org.eclipse.cdt.internal.core.model.CModelManager.getDefault(CModelManager.j
> ava:175)
> at org.eclipse.cdt.core.model.CoreModel.<clinit>(CoreModel.java:68)
> ... 1 more
>
>
> import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
> import org.eclipse.cdt.core.model.CoreModel;
> import org.eclipse.cdt.core.model.ITranslationUnit;
> import org.eclipse.core.runtime.IPath;
> import org.eclipse.core.runtime.Path;
>
> public class JavaApp {
>
> public static void main(String[] args) {
> try
> {
> String FN="C:\\CFILES\\File.c";
> IPath iPath=new Path(FN);
> ITranslationUnit TemplateTransUnit=(ITranslationUnit)
> CoreModel.getDefault().create(iPath);
> IASTTranslationUnit TemplateAST=TemplateTransUnit.getAST();
> System.out.println(TemplateAST.getRawSignature());
> }catch (Exception e) {e.printStackTrace();}
> }
>
> }
>
>
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top