INTRODUCTION I have a patch that I hope the ant team will accept (please, please, please ;-). Basically, the gist of the work is my refactoring the javac task into a different architecture (proxy, factory, etc). I have also introduced three new attributes for the javac task which I'll explain later.
--- REFACTORING --- JAVAC REFACTORING I have taken the javac task and turned it into a proxy. All that it does now is the following: - it accepts attribute values through it's setter methods - in the execute method, it performs some basic checks. (src and dest being set) - execute also still determines the filelist - it then gets a CompilerAdapter (a new interface) from the CompilerAdapterFactory and runs it. (see below for the definition of a compiler factory). It's this adapter that has the responsibility to compile the code. I consider the changes to be stage one of the refactoring process: modification of architecture. Future patches will address things like the cleaning up of internal responsibilities. NEW INTERFACE - CompilerAdapter The purpose of a compiler adapter is to take information from the javac task, interpret it for the compiler that it represents, and then runs the compiler. This interface simply provides two methods: - setJavac -- this gets called by the javac task to populate the adapter. - execute -- this gets called by the javac task if there are files to compile. Because this is an interface, plus how the factory creates instances of this interface, users can very simply add new compilers without having to modify Ant's source code, but still be able to use the javac task. (plug-ins for compilers) NEW CLASS - CompilerAdapterFactory This is a singleton class that simply creates a new instance of CompilerAdapter based on the compiler name that gets passed to it. Not only will it accept the old standards (classic, modern, jikes & jvc), but it will also accept a classname. If the compiler name can't be resolved into one of the four standard categories, the factory treats the name as the name of a class and tries to create a new instance of the classname through reflection. NEW CLASS - DefaultCompilerAdapter This is the default implementation of the compiler adapter. It is an abstract class. It simply contains all the variables and common methods that it's subclasses use. It's subclasses are the four classes listed below. NEW CLASS - Javac12 This is the adapter for the 1.1/1.2 version of the javac compiler. NEW CLASS - Javac13 This is the adapter for the 1.3 version of the javac compiler. NEW CLASS - Jikes This is the adapter for the jikes compiler. It is simply the doJikesCompile() method from the old Javac task. NEW CLASS - Jvc This is the adapter for the Microsoft Jvc compiler. It is simply the doJvcCompile() method from the old Javac task. --- NEW FUNCTIONALITY --- I have added three new attributes to the javac task: - compiler - used by the CompilerAdapterFactory to determine which compiler to use. This will over-ride the "build.compiler" magic variable if it is defined. - includeAntRuntime - whether or not to include the ant runtime libraries in the javac's classpath. default is no. - includeJavaRuntime - whether or not to include the java runtime libraries in the javac's classpath. default is no. compiler: This allows explicit statement of which compiler the user whishes to use. This could also be the classname of a different compiler that the user has created for their own purposes (e.g.: <javac compiler="personel.MyCompiler" .../>). This will allow plug-in compilers. I should note here that the addition of the compiler attribute to the javac task is backwards compatible with the "build.compiler" magic variable. I.e.: if compiler is not set and build.compiler is, then build.compiler will be used to determine which compiler adapter to create. In my humble opinion, the introduction of the compiler attribute is a step towards the elimination of the build.compiler (I believe that Ant wants to eliminate the usage of magic variables). includeAntRuntime: This is one of the two new pieces of functionality that is NOT BACKWARDS COMPATABLE. Currently, when one uses the javac task, they automatically have included in their classpath, things like the ant.jar, jaxp.jar etc. In my opinion, if I didn't ask for it, it shouldn't be included. includeJavaRuntime: This is the second new piece of functionality that is NOT BACKWARDS COMPATABLE. Currently, when one uses the javac task, the automatically have included in their classpath, things like rt.jar which is not necessary. With the modern compiler, it will automatically include it's rt.jar even though it's not in the classpath. The only time the modern compiler doesn't include it is when the bootclasspath parameter is used, and in this case the user doesn't want rt.jar included. Therefore it shouldn't be included unless asked for. --- INCLUDED DIFFS --- I have included the following files: - Execute.java.diff - I needed to change the scope on a method. - index.html.diff - changes to the javac task documentation - Javac.java.diff - the MASSIVE changes to the javac task. Because these changes are so drastic, I have also included the Javac.java.mod file which is my version of the javac task in it's entirety. - CompilerAdapter.java, CompilerAdapterFactory.java, DefaultCompilerAdapter.java, Javac12.java, Javac13.java, Jikes.java, Jvc.java - all these files go into a new package (obviously by their package statement) off the taskdefs called "compilers" --- TESTING --- I have only performed tests using the compilers I have. This includes jikes and javac from 1.2 and 1.3. I have not performed tests using javac 1.1 or jvc. --- CLOSING --- Hopefully you will find the following changes useful. I personally believe that it is a small step in the direction that ant has stated that it wants to go. If you have any questions, please feel free to ask. I'll be monitoring my e-mail and lurking in the ant-dev list during the holidays. Jay Dickon Glanville PS: The sooner these changes get accepted, the sooner I can submit further refactorings and patches to the javac task. <<CompilerAdapter.java>> <<CompilerAdapterFactory.java>> <<DefaultCompilerAdapter.java>> <<Execute.java.diff>> <<index.html.diff>> <<Javac.java.diff>> <<Javac.java.mod>> <<Javac12.java>> <<Javac13.java>> <<Jikes.java>> <<Jvc.java>> ---------------------------------------------------------------------------- ----- Jay Dickon Glanville P068 - SiteManager Development, Nortel Networks 613-765-1144 (ESN 395-1144) MS: 045/55/A05 E-Mail: [EMAIL PROTECTED]
CompilerAdapter.java
Description: Binary data
CompilerAdapterFactory.java
Description: Binary data
DefaultCompilerAdapter.java
Description: Binary data
Execute.java.diff
Description: Binary data
index.html.diff
Description: Binary data
Javac.java.diff
Description: Binary data
Javac.java.mod
Description: Binary data
Javac12.java
Description: Binary data
Javac13.java
Description: Binary data
Jikes.java
Description: Binary data
Jvc.java
Description: Binary data
