Bug 217233 - [compiler] Add compiler API to call the batch compiler from a stand-alone application
Summary: [compiler] Add compiler API to call the batch compiler from a stand-alone app...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P1 enhancement (vote)
Target Milestone: 3.4 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 185118 (view as bug list)
Depends on:
Blocks: 126584 219486
  Show dependency tree
 
Reported: 2008-01-31 05:20 EST by Maxime Daniel CLA
Modified: 2008-08-22 11:08 EDT (History)
9 users (show)

See Also:


Attachments
Proposed API, implementation and tests (50.77 KB, patch)
2008-03-18 14:28 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Same patch with CompilerProgress renamed to CompilationProgress (50.89 KB, patch)
2008-03-19 04:16 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Version that takes a String[] as command line arguments (54.33 KB, patch)
2008-03-20 13:11 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2008-01-31 05:20:27 EST
Some users want to call the batch compiler from their code but without involving the eclipse platform. They have used internal method org.eclipse.jdt.internal.compiler.batch.Main#compile(String commandLine,
PrintWriter outWriter, PrintWriter errWriter), but this is not viable since this is not API.
JSR-199 is not applicable for 1.5 level, while there is a need for 1.5 and maybe even 1.4.2.
There is a need for progress reporting.
Hence the requirement: an API that would have basically the same capabilities as the non-API method above, plus a progress reporting ability that would not depend on any Eclipse platform plugin (aka only depend on ecj.jar), made available for 1.4.2 and above.
Comment 1 Philipe Mulet CLA 2008-01-31 06:18:20 EST
Progress reporting would also need to allow cancellation, which would be good to introduce in compiler, so it would improve cancellation for the Java builder or other tools which are currently relying on compiler I/O to force cancellation (throwing abort compilation).
Comment 2 Jerome Lanneluc CLA 2008-02-19 11:42:34 EST
Kent, since Maxime is too busy on other front, please take care of this bug (this is a must have for M6). Please talk to Philippe or myself if you need clarification.
Comment 3 Eugene Chan CLA 2008-03-13 11:08:24 EDT
In TPTP (bug 187723), internal method org.eclipse.jdt.internal.compiler.batch.Main.compile(String) is called for the same purpose. TPTP needs an API that would have basically the same capabilities
as the non-API. This is part of an effort to remove all internal reference in TPTP.
Please let me know if you need detail about the usage of the API in TPTP.
Comment 4 Eugene Chan CLA 2008-03-13 11:14:22 EDT
Correction: the TPTP bug number should be bug 126584. Not bug 187723.
Comment 5 Jerome Lanneluc CLA 2008-03-18 14:28:22 EDT
Created attachment 92829 [details]
Proposed API, implementation and tests
Comment 6 Philipe Mulet CLA 2008-03-19 01:13:19 EDT
Cosmetical suggestion: what about
CompilerProgress --> CompilationProgress ?
Comment 7 Jerome Lanneluc CLA 2008-03-19 04:16:08 EDT
Created attachment 92871 [details]
Same patch with CompilerProgress renamed to CompilationProgress
Comment 8 Yen Lu CLA 2008-03-19 16:20:43 EDT
I looked at the compiler API and it is taking in a string command line argument. Does this mean that we need to manually add double-quotes for files whose paths have spaces? Wouldn't it be better if Eclipse could handle this for adopters and adopters be allowed to pass in an array of arguments instead?
Comment 9 Alex Nan CLA 2008-03-20 00:35:11 EDT
I have ported our code to use the new API and it looks OK to me. I've also
tested progress monitoring and cancelation. The only thing that looks a bit
confusing is that there apparently is no distinction between a cancelation and
a compile error, the API returns in both cases false.
Regarding comment #8, indeed I had to quote source file paths that were containing spaces.
Comment 10 Eugene Chan CLA 2008-03-20 09:40:55 EDT
I tried migrate my code to the new API and it looks ok to me. However I agree with Lu that it's better if the API handle whitespace within path.
Comment 11 Jerome Lanneluc CLA 2008-03-20 12:10:51 EDT
(In reply to comment #9)
> I have ported our code to use the new API and it looks OK to me. I've also
> tested progress monitoring and cancelation. The only thing that looks a bit
> confusing is that there apparently is no distinction between a cancelation and
> a compile error, the API returns in both cases false.
To distinguish between cancelation and a compile error, the client can still ask the compilation progress if it was canceled: CompilationProgress#isCanceled()

> Regarding comment #8, indeed I had to quote source file paths that were
> containing spaces.
I will add a new method that takes a String array to avoid this.

Comment 12 Alex Nan CLA 2008-03-20 12:43:35 EDT
Re: comment #11 , you are right, the progress monitor can be queried to find out whether the task has been canceled.
An additional method taking an array of strings would be useful for sure, it would make the API more flexible. 
Thanks.
Comment 13 Jerome Lanneluc CLA 2008-03-20 13:11:02 EDT
Created attachment 93047 [details]
Version that takes a String[] as command line arguments
Comment 14 Jerome Lanneluc CLA 2008-03-21 13:00:44 EDT
API, implementation and tests released for 3.4M6
Comment 15 David Audel CLA 2008-03-25 12:29:15 EDT
Verified for 3.4M6 using build I20080324-1300.
Comment 16 Jerome Lanneluc CLA 2008-08-22 11:08:11 EDT
*** Bug 185118 has been marked as a duplicate of this bug. ***