/*
* Name: JavaCompiler
* Authors: Richard Rodger
*
* Copyright (c) 2004 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
// package
package org.jostraca.process;
// import
import org.jostraca.PropertyJava;
import org.jostraca.Template;
import org.jostraca.util.TextUtil;
import org.jostraca.util.Standard;
import org.jostraca.util.PropertySet;
import org.jostraca.util.BasicWayPoint;
import org.jostraca.util.WayPointRecorder;
import java.util.List;
import java.util.Iterator;
import java.io.File;
/** Support class for Java compiler processing classes.
*/
public class JavaCompiler extends GenericCompiler {
private InternalJavaCompiler iInternalJavaCompiler = null;
private ExternalJavaCompiler iExternalJavaCompiler = null;
public JavaCompiler() {
// do nothing
}
/** JavaCompilers must be stateless and reentrant
*/
protected void compileAsFirst( List pTemplateList ) {
if( null == iInternalJavaCompiler ) {
iInternalJavaCompiler = new InternalJavaCompiler();
}
if( iInternalJavaCompiler.canCompile() ) {
System.out.println("internal");
iInternalJavaCompiler.setUserMessageHandler( mUserMessageHandler );
iInternalJavaCompiler.compileAsFirst( pTemplateList );
}
else {
if( null == iExternalJavaCompiler ) {
iExternalJavaCompiler = new ExternalJavaCompiler();
}
iExternalJavaCompiler.setUserMessageHandler( mUserMessageHandler );
iExternalJavaCompiler.compileAsFirst( pTemplateList );
}
}
protected boolean makeCompileList( List pTemplateList, StringBuffer pSourceFilesBuffer, List pSourceFilesList ) {
List tmlist = pTemplateList;
StringBuffer sourceFilesB = pSourceFilesBuffer;
boolean compile = false;
for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
Template tm = (Template) tmT.next();
File executablePath = makeExecutablePath( tm );
tm.setCodeWriterExecutablePath( executablePath );
boolean compileRequired = compileRequired( tm );
if( compileRequired ) {
File cwF = tm.getCodeWriterPath();
sourceFilesB.append( " "+TextUtil.quoteSpaces( cwF.getPath() ) );
pSourceFilesList.add( cwF.getPath() );
WayPointRecorder.add( BasicWayPoint.CompilingCodeWriter.make( cwF.getAbsolutePath() ) );
compile = true;
}
}
return compile;
}
protected File makeExecutablePath( Template pTemplate ) {
File cwp = pTemplate.getCodeWriterPath();
File parent = cwp.getParentFile();
String name = cwp.getName();
int dotJavaIndex = name.lastIndexOf( Standard.DOT );
PropertySet tmps = pTemplate.getMergedPropertySet();
String cf = tmps.get( PropertyJava.ClassFolder );
if( !"".equals( cf ) ) {
parent = new File( cf );
}
File epf = cwp;
if( -1 != dotJavaIndex ) {
name = name.substring( 0, dotJavaIndex)+JavaUtil.FILE_EXT_dotClass;
epf =
null == parent
? new File( name )
: new File( parent, name )
;
}
return epf;
}
}