Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » JavaCompilerTool as a builder
JavaCompilerTool as a builder [message #226089] Mon, 20 March 2006 06:48 Go to next message
Eclipse UserFriend
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 #226300 is a reply to message #226089] Wed, 22 March 2006 02:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: onlinenews.emanuelgreisen.dk

Ok, I am working on a Mustang-builder and everything is working out real
nice. But once I started accessing the org.eclipse.jdt.core.* package
the plugin stopped working.

Here is the error I get:

java.lang.NoClassDefFoundError: org/eclipse/jdt/core/IJavaProject
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:23 59)
at java.lang.Class.getConstructor0(Class.java:2667)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at
org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI .createExecutableExtension(RegistryStrategyOSGI.java:148)
at
org.eclipse.core.internal.registry.ExtensionRegistry.createE xecutableExtension(ExtensionRegistry.java:759)
at
org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutableExtension(ConfigurationElement.java:243)
at
org.eclipse.core.internal.registry.ConfigurationElementHandl e.createExecutableExtension(ConfigurationElementHandle.java: 51)
at
org.eclipse.core.internal.events.BuildManager.instantiateBui lder(BuildManager.java:749)
at
org.eclipse.core.internal.events.BuildManager.initializeBuil der(BuildManager.java:701)
at
org.eclipse.core.internal.events.BuildManager.getBuilder(Bui ldManager.java:442)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:200)
at
org.eclipse.core.internal.events.BuildManager$1.run(BuildMan ager.java:231)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:234)
at
org.eclipse.core.internal.events.BuildManager.basicBuildLoop (BuildManager.java:253)
at
org.eclipse.core.internal.events.BuildManager.build(BuildMan ager.java:282)
at
org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBu ildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJ ob.java:204)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)




Looking at my plugin-settings, under the "Dependencies"-tab I have
org.eclipse.jdt.core, what else do I need ?

I have been looking at the source-code for gcjbuilder (it also accesses
the IJavaProject and similar classes) and I have been unable to figure
out what they do that I don't.

Anyone ?
Re: JavaCompilerTool as a builder [message #226309 is a reply to message #226300] Wed, 22 March 2006 06:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: onlinenews.emanuelgreisen.dk

Well I finally got it running. I am uncertain as to what the error
really was, but once I configured my build to contain a "Runtime"-jar
with my class-files in, it all worked.

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.
Re: JavaCompilerTool as a builder [message #226352 is a reply to message #226309] Wed, 22 March 2006 22:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomann.NOca.ibm.comSPAM

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 #226375 is a reply to message #226352] Thu, 23 March 2006 04:29 Go to previous messageGo to next message
Eclipse UserFriend
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 #226406 is a reply to message #226352] Thu, 23 March 2006 15:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: onlinenews.emanuelgreisen.dk

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 é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 #226445 is a reply to message #226406] Fri, 24 March 2006 00:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: onlinenews.emanuelgreisen.dk

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 é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 #226460 is a reply to message #226445] Fri, 24 March 2006 06:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: onlinenews.emanuelgreisen.dk

I figured out how to follow the compilation, and it works great. But, I
would like my builder to run after the "normal" eclipse builder. Reading
about the CompilationParticipant-class I figured that I can order the
participants with requirements of other participants. Is the eclipse
compiler it-self a participant ? In that case what is the name of it, so
that I can make my builder run after the eclipse-compiler.

Thx.
Re: JavaCompilerTool as a builder [message #226478 is a reply to message #226460] Fri, 24 March 2006 10:30 Go to previous messageGo to next message
Eclipse UserFriend
Emanuel Greisen a écrit :
> I figured out how to follow the compilation, and it works great. But, I
> would like my builder to run after the "normal" eclipse builder. Reading
> about the CompilationParticipant-class I figured that I can order the
> participants with requirements of other participants. Is the eclipse
> compiler it-self a participant ? In that case what is the name of it, so
> that I can make my builder run after the eclipse-compiler.
The Java compiler is not a compilation participant, but APT is.
You should define an extension point for
org.eclipse.core.resources.builders.
Look at the code in org.eclipse.jdt.internal.core.builder.JavaBuilder.

Processing the deltas should allow you to achieve what you want to do.
You should then register your builder as the builder for java file and
disable the current Java builder.

HTH,
--
Olivier
Re: JavaCompilerTool as a builder [message #227645 is a reply to message #226445] Wed, 12 April 2006 07:16 Go to previous message
Eclipse UserFriend
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
Previous Topic:workspace not opened
Next Topic:Eclipse 3.2M6 fails to process action-related keybindings
Goto Forum:
  


Current Time: Mon Nov 10 02:26:42 EST 2025

Powered by FUDForum. Page generated in 0.05614 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top