edu.rice.cs.drjava.model.compiler
Class CompilerProxy

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.compiler.CompilerProxy
All Implemented Interfaces:
CompilerInterface
Direct Known Subclasses:
GJv6FromClasspath, Javac141FromClasspath, Javac141FromSetLocation, Javac141FromToolsJar, JavacFromClasspath, JavacFromSetLocation, JavacFromToolsJar, JSR14FromSetLocation, JSR14v12FromSetLocation

public class CompilerProxy
extends Object
implements CompilerInterface

A compiler interface to search a given

Version:
$Id: CompilerProxy.java,v 1.13 2002/09/13 22:55:34 csreis Exp $

Field Summary
private  String _className
           
private  ClassLoader _newLoader
           
private  CompilerInterface _realCompiler
          The actual compiler interface.
private static String[] _useOldLoader
          These classes will always be loaded using the previous classloader.
 
Constructor Summary
CompilerProxy(String className, ClassLoader newLoader)
          A proxy compiler interface that tries to load the given class from one of the given locations.
 
Method Summary
private  void _recreateCompiler()
           
 void addToBootClassPath(File cp)
          This method allows us to set the JSR14 collections path across a class loader.
 CompilerError[] compile(File[] sourceRoots, File[] files)
          Compile the given files.
 CompilerError[] compile(File sourceRoot, File[] files)
          Compile the given files.
 String getName()
          Returns the name of this compiler, appropriate to show to the user.
 boolean isAvailable()
          Indicates whether this compiler is actually available.
 void setAllowAssertions(boolean allow)
          Sets whether to allow assertions in Java 1.4.
 void setExtraClassPath(String extraClassPath)
          Allows us to set the extra classpath for the compilers without referencing the config object in a loaded class file
 String toString()
          Should return info about compiler, at least including name.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

_realCompiler

private CompilerInterface _realCompiler
The actual compiler interface. If it's null, we couldn't load it.

_className

private final String _className

_newLoader

private final ClassLoader _newLoader

_useOldLoader

private static final String[] _useOldLoader
These classes will always be loaded using the previous classloader. This is important to make sure there is only one instance of them, so their values can be freely passed about the program.
Constructor Detail

CompilerProxy

public CompilerProxy(String className,
                     ClassLoader newLoader)
A proxy compiler interface that tries to load the given class from one of the given locations. It uses its own classloader, which will even allow loading a second instance of the class!
Parameters:
className - Implementation of CompilerInterface to proxy for.
loader - Classloader to use
Method Detail

_recreateCompiler

private void _recreateCompiler()

compile

public CompilerError[] compile(File sourceRoot,
                               File[] files)
Compile the given files.
Specified by:
compile in interface CompilerInterface
Parameters:
files - Source files to compile.
sourceRoot - Source root directory, the base of the package structure.
Returns:
Array of errors that occurred. If no errors, should be zero length array (not null).

compile

public CompilerError[] compile(File[] sourceRoots,
                               File[] files)
Compile the given files.
Specified by:
compile in interface CompilerInterface
Parameters:
files - Source files to compile.
sourceRoots - Array of source root directories, the base of the package structure for all files to compile.
Returns:
Array of errors that occurred. If no errors, should be zero length array (not null).

isAvailable

public boolean isAvailable()
Indicates whether this compiler is actually available. As in: Is it installed and located? This method should load the compiler class, which should hopefully prove whether the class can load. If this method returns true, the compile(java.io.File, java.io.File[]) method should not fail due to class not being found.
Specified by:
isAvailable in interface CompilerInterface

getName

public String getName()
Returns the name of this compiler, appropriate to show to the user.
Specified by:
getName in interface CompilerInterface

toString

public String toString()
Should return info about compiler, at least including name.
Specified by:
toString in interface CompilerInterface
Overrides:
toString in class Object

setExtraClassPath

public void setExtraClassPath(String extraClassPath)
Allows us to set the extra classpath for the compilers without referencing the config object in a loaded class file
Specified by:
setExtraClassPath in interface CompilerInterface

setAllowAssertions

public void setAllowAssertions(boolean allow)
Sets whether to allow assertions in Java 1.4.
Specified by:
setAllowAssertions in interface CompilerInterface

addToBootClassPath

public void addToBootClassPath(File cp)
This method allows us to set the JSR14 collections path across a class loader. (cannot cast a loaded class to a subclass, so all compiler interfaces must have this method)
Specified by:
addToBootClassPath in interface CompilerInterface