| JavaCompilerTool as a builder [message #226089] |
Mon, 20 March 2006 06:48  |
Eclipse User |
|
|
|
Originally posted by: onlinenews.emanuelgreisen.dk
Hi there,
Is there anyone who knows if the new JDK1.6 (Mustang) class
"JavaCompilerTool" can be used as a builder in Eclipse ? This would be a
great feature since at least the javac from Mustang handles
parameterized types much better.
../Emanuel
|
|
|
|
|
|
| Re: JavaCompilerTool as a builder [message #226375 is a reply to message #226352] |
Thu, 23 March 2006 04:29   |
Eclipse User |
|
|
|
Originally posted by: onlinenews.emanuelgreisen.dk
I am using the JavaCompilerTool of JAVA1.6
http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompil erTool.html
Here are two bits of code to give you an idea of how its done:
[Snippet setting up the Compiler]
private void setupCompiler(IJavaProject project2) throws CoreException
{
if(_persistant_compiler == null || project != project2)
{
project = project2;
workspacePath =
ResourcesPlugin.getWorkspace().getRoot().getLocation().toFil e();
try
{
System.out.println("Getting a default JAVAC-compiler[From: "+ (new
File(".")).getAbsolutePath() + "]");
// Just get the compiler
_persistant_compiler = ToolProvider.defaultJavaCompiler();
// Set our classpaths
_persistant_compiler.setClassPath(getClassPaths());
File outputdir = getJavaOutputDir(project);
System.out.println("Output: " + outputdir);
//project.get
_persistant_compiler.setOutputDirectory(outputdir);
// FIXME: we should set this too:
// getCompiler().setSourcePath(arg0)
// project.get
_persistant_compiler.setSourcePath(getProjectSourceFolders() );
// DEBUG: Just creating a debug JAVAC-command:
debug_javac_cmd = "javac -classpath \"";
for(File f : getClassPaths())
{
debug_javac_cmd += f.getAbsolutePath()+":";
}
debug_javac_cmd += "\" \\\n -sourcepath \"";
for(File f : getProjectSourceFolders())
{
debug_javac_cmd += f.getAbsolutePath()+":";
}
debug_javac_cmd += "\" \\\n -d "+outputdir+" \\\n ";
}
catch (CoreException e)
{
e.printStackTrace();
_persistant_compiler = null;
throw e;
}
}
}
[/snippet]
[Snippet that uses the compiler to compile a single file, and gets the
reported errors/warning/infos directly from the compiler using the
"compiler.setDiagnosticListener(this);"]
public void compile()
{
System.out.println("About to compile: " +
file.getLocation().toOSString());
try
{
JavaCompilerTool compiler = getCompiler();
// Hook into the compiler (listen for errors)
compiler.setDiagnosticListener(this);
// Get source of the file (TODO: we could use the IFile to get
// the content... somehow, and maybe we should sync with
// file-system or something).
JavaFileObject javafile =
compiler.getStandardFileManager().getFileForInput(file.getLo cation().toOSString());
// Compile the file,
task = compiler.run(null, javafile /* ... */);
task.run();
// unregister our listening
getCompiler().setDiagnosticListener(null);
}
catch (IOException e)
{
e.printStackTrace();
MustangBuilder.this.addMarker(file, e.getMessage(), 0,
IMarker.SEVERITY_ERROR);
}
catch(Exception e)
{
e.printStackTrace();
}
}
[/snippet]
If you are intersted I can send you the entire project, or maybe start a
sf.net-project on this.
Olivier Thomann wrote:
> Emanuel Greisen a écrit :
>
>> If anyone has any interest in a builder using the new JavaCompiler-API
>> from Mustang let me know, I will be happy to share it.
>
> Are you calling javac or you wrote a wrapper of the Eclipse compiler?
> --
> Olivier
|
|
|
|
|
|
|
| Re: JavaCompilerTool as a builder [message #227645 is a reply to message #226445] |
Wed, 12 April 2006 07:16  |
Eclipse User |
|
|
|
Will look into bug 81949. Note that there are several situations where our
compiler will disagree with javac, and in numerous cases, there is a
corresponding bug in javac database... So your argument feels a bit biased.
For production mode, our builder relies on our compiler to compute some
dependency information. So if you compile twice the files (once with our
compiler, once with some other tool) it will have big performance penalty.
But this is really your call.
Last but not least, all the tool stack is currently tightly integrated; e.g.
the error you see in editor is the error you get when building, or
codeassisting etc... you would loose this.
If you find a decent bug in the compiler, feel free to contribute a patch
for it, we will consider it.
"Emanuel Greisen" <onlinenews@emanuelgreisen.dk> wrote in message
news:e001be$r7f$1@utils.eclipse.org...
> It seems like its the CompilerParticipant that I need to inherit from,
> and that will somehow enable be to follow the compilation/Reconciling.
>
> Is there an example of how to do this somewhere ?
>
> ./Emanuel
>
> Emanuel Greisen wrote:
> > I read on the Eclipse site that Eclipse 3.2 should have some way of
> > "following" the builder while its building. I have not been able to find
> > out how this should be done. The reason I ask is that my mustang builder
> > is working "alright" now, but it has no idea what resources to rebuild
> > when one of them changes. I would really like to use the Eclipse
> > Java-compiler to find my way around everything, but use Mustang to do
> > the actual compilation (because Eclipse cannot handle heavy heavy
> > generic type stuff, [Bugzilla 81949])
> >
> > Maybe someone could give me a pointer as to how I could "hook" into the
> > JavaCompiler.
> >
> > Thx.
> >
> > Olivier Thomann wrote:
> >
> >> Emanuel Greisen a
|
|
|
Powered by
FUDForum. Page generated in 0.05567 seconds