@@ -11,6 +11,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.taskdefs.Javac;
@@ -29,28 +30,30 @@ import org.apache.tools.ant.types.Path;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*/
*/
public abstract class DefaultCompilerAdapter implements CompilerAdapter
public abstract class DefaultCompilerAdapter
extends AbstractLogEnabled
implements CompilerAdapter
{
{
protected static String lSep = System.getProperty( "line.separator" );
protected boolean debug = false ;
protected boolean optimize = fals e;
protected boolean deprecation = false ;
protected boolean depend = false ;
protected boolean verbose = fal se;
protected Javac attributes;
protected Path bootclasspath;
protected Path compileClasspath;
protected File[] compileList;
protected File destDir;
protected String encoding;
protected Path extdirs;
protected boolean includeAntRuntime;
protected boolean includeJavaRuntime;
protected String memoryInitialSize;
protected String memoryMaximumSize;
protected Project project;
protected static String LINE_SEP = System.getProperty( "line.separator" );
protected boolean m_ debug;
protected boolean m_ optimize;
protected boolean m_ deprecation;
protected boolean m_ depend;
protected boolean m_ verbose;
protected Javac m_ attributes;
protected Path m_ bootclasspath;
protected Path m_ compileClasspath;
protected File[] m_ compileList;
protected File m_ destDir;
protected String m_ encoding;
protected Path m_ extdirs;
protected boolean m_ includeAntRuntime;
protected boolean m_ includeJavaRuntime;
protected String m_m emoryInitialSize;
protected String m_m emoryMaximumSize;
protected Project m_ project;
/*
/*
* jdg - TODO - all these attributes are currently protected, but they
* jdg - TODO - all these attributes are currently protected, but they
@@ -61,30 +64,30 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
public void setJavac( Javac attributes )
public void setJavac( Javac attributes )
{
{
this.attributes = attributes;
this.m_ attributes = attributes;
src = attributes.getSrcdir();
src = attributes.getSrcdir();
destDir = attributes.getDestdir();
encoding = attributes.getEncoding();
debug = attributes.getDebug();
optimize = attributes.getOptimize();
deprecation = attributes.getDeprecation();
depend = attributes.getDepend();
verbose = attributes.getVerbose();
m_ destDir = attributes.getDestdir();
m_ encoding = attributes.getEncoding();
m_ debug = attributes.getDebug();
m_ optimize = attributes.getOptimize();
m_ deprecation = attributes.getDeprecation();
m_ depend = attributes.getDepend();
m_ verbose = attributes.getVerbose();
target = attributes.getTarget();
target = attributes.getTarget();
bootclasspath = attributes.getBootclasspath();
extdirs = attributes.getExtdirs();
compileList = attributes.getFileList();
compileClasspath = attributes.getClasspath();
project = attributes.getProject();
includeAntRuntime = attributes.getIncludeantruntime();
includeJavaRuntime = attributes.getIncludejavaruntime();
memoryInitialSize = attributes.getMemoryInitialSize();
memoryMaximumSize = attributes.getMemoryMaximumSize();
m_ bootclasspath = attributes.getBootclasspath();
m_ extdirs = attributes.getExtdirs();
m_ compileList = attributes.getFileList();
m_ compileClasspath = attributes.getClasspath();
m_ project = attributes.getProject();
m_ includeAntRuntime = attributes.getIncludeantruntime();
m_ includeJavaRuntime = attributes.getIncludejavaruntime();
m_m emoryInitialSize = attributes.getMemoryInitialSize();
m_m emoryMaximumSize = attributes.getMemoryMaximumSize();
}
}
public Javac getJavac()
public Javac getJavac()
{
{
return attributes;
return m_ attributes;
}
}
protected Commandline setupJavacCommand()
protected Commandline setupJavacCommand()
@@ -128,46 +131,46 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
// has its own parameter format
// has its own parameter format
boolean usingJava1_1 = Project.getJavaVersion().equals( Project.JAVA_1_1 );
boolean usingJava1_1 = Project.getJavaVersion().equals( Project.JAVA_1_1 );
String memoryParameterPrefix = usingJava1_1 ? "-J-" : "-J-X";
String memoryParameterPrefix = usingJava1_1 ? "-J-" : "-J-X";
if( memoryInitialSize != null )
if( m_m emoryInitialSize != null )
{
{
if( !attributes.isForkedJavac() )
if( !m_ attributes.isForkedJavac() )
{
{
attributes.log( "Since fork is false, ignoring memoryInitialSize setting.",
Project.MSG_WARN );
final String message = "Since fork is false, ignoring memoryInitialSize setting.";
getLogger().warn( message );
}
}
else
else
{
{
cmd.createArgument().setValue( memoryParameterPrefix + "ms" + memoryInitialSize );
cmd.createArgument().setValue( memoryParameterPrefix + "ms" + m_m emoryInitialSize );
}
}
}
}
if( memoryMaximumSize != null )
if( m_m emoryMaximumSize != null )
{
{
if( !attributes.isForkedJavac() )
if( !m_ attributes.isForkedJavac() )
{
{
attributes.log( "Since fork is false, ignoring memoryMaximumSize setting.",
Project.MSG_WARN );
final String message = "Since fork is false, ignoring memoryMaximumSize setting.";
getLogger().warn( message );
}
}
else
else
{
{
cmd.createArgument().setValue( memoryParameterPrefix + "mx" + memoryMaximumSize );
cmd.createArgument().setValue( memoryParameterPrefix + "mx" + m_m emoryMaximumSize );
}
}
}
}
if( attributes.getNowarn() )
if( m_ attributes.getNowarn() )
{
{
cmd.createArgument().setValue( "-nowarn" );
cmd.createArgument().setValue( "-nowarn" );
}
}
if( deprecation == true )
if( m_ deprecation == true )
{
{
cmd.createArgument().setValue( "-deprecation" );
cmd.createArgument().setValue( "-deprecation" );
}
}
if( destDir != null )
if( m_ destDir != null )
{
{
cmd.createArgument().setValue( "-d" );
cmd.createArgument().setValue( "-d" );
cmd.createArgument().setFile( destDir );
cmd.createArgument().setFile( m_ destDir );
}
}
cmd.createArgument().setValue( "-classpath" );
cmd.createArgument().setValue( "-classpath" );
@@ -176,17 +179,17 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
// as well as "bootclasspath" and "extdirs"
// as well as "bootclasspath" and "extdirs"
if( Project.getJavaVersion().startsWith( "1.1" ) )
if( Project.getJavaVersion().startsWith( "1.1" ) )
{
{
Path cp = new Path( project );
Path cp = new Path( m_ project );
/*
/*
* XXX - This doesn't mix very well with build.systemclasspath,
* XXX - This doesn't mix very well with build.systemclasspath,
*/
*/
if( bootclasspath != null )
if( m_ bootclasspath != null )
{
{
cp.append( bootclasspath );
cp.append( m_ bootclasspath );
}
}
if( extdirs != null )
if( m_ extdirs != null )
{
{
cp.addExtdirs( extdirs );
cp.addExtdirs( m_ extdirs );
}
}
cp.append( classpath );
cp.append( classpath );
cp.append( src );
cp.append( src );
@@ -202,31 +205,31 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
cmd.createArgument().setValue( "-target" );
cmd.createArgument().setValue( "-target" );
cmd.createArgument().setValue( target );
cmd.createArgument().setValue( target );
}
}
if( bootclasspath != null )
if( m_ bootclasspath != null )
{
{
cmd.createArgument().setValue( "-bootclasspath" );
cmd.createArgument().setValue( "-bootclasspath" );
cmd.createArgument().setPath( bootclasspath );
cmd.createArgument().setPath( m_ bootclasspath );
}
}
if( extdirs != null )
if( m_ extdirs != null )
{
{
cmd.createArgument().setValue( "-extdirs" );
cmd.createArgument().setValue( "-extdirs" );
cmd.createArgument().setPath( extdirs );
cmd.createArgument().setPath( m_ extdirs );
}
}
}
}
if( encoding != null )
if( m_ encoding != null )
{
{
cmd.createArgument().setValue( "-encoding" );
cmd.createArgument().setValue( "-encoding" );
cmd.createArgument().setValue( encoding );
cmd.createArgument().setValue( m_ encoding );
}
}
if( debug )
if( m_ debug )
{
{
if( useDebugLevel
if( useDebugLevel
&& Project.getJavaVersion() != Project.JAVA_1_0
&& Project.getJavaVersion() != Project.JAVA_1_0
&& Project.getJavaVersion() != Project.JAVA_1_1 )
&& Project.getJavaVersion() != Project.JAVA_1_1 )
{
{
String debugLevel = attributes.getDebugLevel();
String debugLevel = m_ attributes.getDebugLevel();
if( debugLevel != null )
if( debugLevel != null )
{
{
cmd.createArgument().setValue( "-g:" + debugLevel );
cmd.createArgument().setValue( "-g:" + debugLevel );
@@ -246,12 +249,12 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
{
{
cmd.createArgument().setValue( "-g:none" );
cmd.createArgument().setValue( "-g:none" );
}
}
if( optimize )
if( m_ optimize )
{
{
cmd.createArgument().setValue( "-O" );
cmd.createArgument().setValue( "-O" );
}
}
if( depend )
if( m_ depend )
{
{
if( Project.getJavaVersion().startsWith( "1.1" ) )
if( Project.getJavaVersion().startsWith( "1.1" ) )
{
{
@@ -263,12 +266,12 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
}
}
else
else
{
{
attributes.log( "depend attribute is not supported by the modern compiler",
Project.MSG_WARN );
final String message = "depend attribute is not supported by the modern compiler";
getLogger().warn( message );
}
}
}
}
if( verbose )
if( m_ verbose )
{
{
cmd.createArgument().setValue( "-verbose" );
cmd.createArgument().setValue( "-verbose" );
}
}
@@ -305,10 +308,10 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
throws TaskException
throws TaskException
{
{
setupJavacCommandlineSwitches( cmd, true );
setupJavacCommandlineSwitches( cmd, true );
if( attributes.getSource() != null )
if( m_ attributes.getSource() != null )
{
{
cmd.createArgument().setValue( "-source" );
cmd.createArgument().setValue( "-source" );
cmd.createArgument().setValue( attributes.getSource() );
cmd.createArgument().setValue( m_ attributes.getSource() );
}
}
return cmd;
return cmd;
}
}
@@ -321,39 +324,39 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
protected Path getCompileClasspath()
protected Path getCompileClasspath()
throws TaskException
throws TaskException
{
{
Path classpath = new Path( project );
Path classpath = new Path( m_ project );
// add dest dir to classpath so that previously compiled and
// add dest dir to classpath so that previously compiled and
// untouched classes are on classpath
// untouched classes are on classpath
if( destDir != null )
if( m_ destDir != null )
{
{
classpath.setLocation( destDir );
classpath.setLocation( m_ destDir );
}
}
// Combine the build classpath with the system classpath, in an
// Combine the build classpath with the system classpath, in an
// order determined by the value of build.classpath
// order determined by the value of build.classpath
if( compileClasspath == null )
if( m_ compileClasspath == null )
{
{
if( includeAntRuntime )
if( m_ includeAntRuntime )
{
{
classpath.addExisting( Path.systemClasspath );
classpath.addExisting( Path.systemClasspath );
}
}
}
}
else
else
{
{
if( includeAntRuntime )
if( m_ includeAntRuntime )
{
{
classpath.addExisting( compileClasspath.concatSystemClasspath( "last" ) );
classpath.addExisting( m_ compileClasspath.concatSystemClasspath( "last" ) );
}
}
else
else
{
{
classpath.addExisting( compileClasspath.concatSystemClasspath( "ignore" ) );
classpath.addExisting( m_ compileClasspath.concatSystemClasspath( "ignore" ) );
}
}
}
}
if( includeJavaRuntime )
if( m_ includeJavaRuntime )
{
{
classpath.addJavaRuntime();
classpath.addJavaRuntime();
}
}
@@ -435,9 +438,9 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
try
try
{
{
final Execute exe = new Execute();
final Execute exe = new Execute();
exe.setOutput( new LogOutputStream( attributes, Project.MSG_INFO ) );
exe.setError( new LogOutputStream( attributes, Project.MSG_WARN ) );
exe.setWorkingDirectory( project.getBaseDir() );
exe.setOutput( new LogOutputStream( m_ attributes, Project.MSG_INFO ) );
exe.setError( new LogOutputStream( m_ attributes, Project.MSG_WARN ) );
exe.setWorkingDirectory( m_ project.getBaseDir() );
exe.setCommandline( commandArray );
exe.setCommandline( commandArray );
return exe.execute();
return exe.execute();
}
}
@@ -464,27 +467,25 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter
*/
*/
protected void logAndAddFilesToCompile( Commandline cmd )
protected void logAndAddFilesToCompile( Commandline cmd )
{
{
attributes.log( "Compilation args: " + cmd.toString(),
Project.MSG_VERBOSE );
getLogger().debug( "Compilation args: " + cmd.toString() );
StringBuffer niceSourceList = new StringBuffer( "File" );
StringBuffer niceSourceList = new StringBuffer( "File" );
if( compileList.length != 1 )
if( m_ compileList.length != 1 )
{
{
niceSourceList.append( "s" );
niceSourceList.append( "s" );
}
}
niceSourceList.append( " to be compiled:" );
niceSourceList.append( " to be compiled:" );
niceSourceList.append( lSep );
niceSourceList.append( LINE_SEP );
for( int i = 0; i < compileList.length; i++ )
for( int i = 0; i < m_ compileList.length; i++ )
{
{
String arg = compileList[ i ].getAbsolutePath();
String arg = m_ compileList[ i ].getAbsolutePath();
cmd.createArgument().setValue( arg );
cmd.createArgument().setValue( arg );
niceSourceList.append( " " + arg + lSep );
niceSourceList.append( " " + arg + LINE_SEP );
}
}
attributes.log( niceSourceList.toString(), Project.MSG_VERBOSE );
getLogger().debug( niceSourceList.toString() );
}
}
}
}