Build file for BeanShel

Brian Hawkins <brianhks-BYHubErIwDGZvNlLnfxc/[email protected]> Mon, 31 Jan 2005 22:14:50 -0700
Newsgroups gmane.comp.java.beanshell.user,gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
Being frustrated with the lack of flexibility of current make systems I 
developed my own.  CPMake is written in Java and the build scripts can 
be written in BeanShell.
I would like to get some more feedback on this project so I have written 
a build script for building BeanShell.  See the attached file.  Save 
this file to the root of the BeanShell project and then download the 
file cpmake_bsh.jar from the cpmake web site www.cpmake.org.  This file 
has the cpmake binaries and the BeanShell 1.3 interpreter in it.

You can then build BeanShell by running "java -jar cpmake_bsh.jar <target>"

To keep from cluttering up this list with feedback you can send email 
directly to me or use the mail list on sourceforge for cpmake.

Thanks in advance

Brian
build.bsh (text/plain, 13.6 KB)
version				= "2.0b2";
deprecation			= "on";
src_dir 			= "src";
build_dir 			= "classes";
lib_dir 			= "lib";
dist_dir			= "dist";
test_src_dir 		= "tests/classes";
javadoc_dir 		= "javadoc";
bsf_src_dir 		= "bsf/src";
classgen_src_dir 	= "asm/src";

javadoc_jar 			= dist_dir+"/javadoc.zip";
core_jar 				= dist_dir+"/bsh-core-"+version+".jar";
src_jar 				= dist_dir+"/bsh-"+version+"-src.jar";
all_jar_name 			= "bsh-"+version+".jar";
all_jar 				= dist_dir+"/"+all_jar_name;
commands_jar 			= dist_dir+"/bsh-commands-"+version+".jar";
classpath_jar 			= dist_dir+"/bsh-classpath-"+version+".jar";
reflect_jar 			= dist_dir+"/bsh-reflect-"+version+".jar";
util_jar 				= dist_dir+"/bsh-util-"+version+".jar";
bsf_jar 				= dist_dir+"/bsh-bsf-"+version+".jar";
classgen_jar 			= dist_dir+"/bsh-classgen-"+version+".jar";
bshservlet_wbsh_war 	= dist_dir+"/bshservlet-wbsh.war";
bshservlet_war 			= dist_dir+"/bshservlet.war";

commands_bshdoc 		= "docs/manual/bshcommands-bshdoc.xml";

//-------------------------------------------------------------------
//==-- JAR FILES TO ADD TO CLASSPATH --==
lib_fileset = make.createFileList(lib_dir, ".*\\.jar",
		(make.INCLUDE_PATH | make.RECURSE));
classpath = build_dir;
for (jarfile : lib_fileset)
	classpath += File.pathSeparator+jarfile;

//-------------------------------------------------------------------
//==-- SET SEARCH PATHS --==
make.addSearchPath(".*\\.java", src_dir);
make.addSearchPath(".*\\.java", classgen_src_dir);
make.addSearchPath(".*\\.java", bsf_src_dir);
make.addSearchPath(".*\\.java", test_src_dir);

//-------------------------------------------------------------------
//==-- DIRECTORY CREATION RULES --==
make.createDirectoryRule(build_dir, null, true);
make.createDirectoryRule(dist_dir, null, true);
make.createDirectoryRule(javadoc_dir, null, true);

//-------------------------------------------------------------------
//==-- RULE FOR bsh.jj --==
make.createExplicitRule(src_dir+"/bsh/bsh.jj", src_dir+"/bsh/bsh.jjt", "jjtree", true);
jjtree(String target, String[] prereqs)
	{
	print("Running jjtree");
	cmd = "java -classpath "+classpath+
		" jjtree -OUTPUT_DIRECTORY="+src_dir+"/bsh "+src_dir+"/bsh/bsh.jjt";
	make.exec(cmd);
	}

//-------------------------------------------------------------------
//==-- RULE FOR Parser.java --==
make.createExplicitRule(src_dir+"/bsh/Parser.java", src_dir+"/bsh/bsh.jjt", "javacc", true);
javacc(String target, String[] prereqs)
	{
	print("Running javacc");
	cmd = "java -classpath "+classpath+
		" javacc -OUTPUT_DIRECTORY="+src_dir+"/bsh "+src_dir+"/bsh/bsh.jj";
	make.exec(cmd);
	}	

make.buildTarget(src_dir+"/bsh/Parser.java");


//-------------------------------------------------------------------
//==-- CREATE SOURCE AND CLASS FILE LISTS --==
sourceFiles = make.createFileList(src_dir, ".*\\.java", 
		(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH));
sourceFiles = make.combine(sourceFiles, make.createFileList(test_src_dir, ".*\\.java",
		(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)));
sourceFiles = make.combine(sourceFiles, make.createFileList(bsf_src_dir, ".*\\.java",
		(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)));
sourceFiles = make.combine(sourceFiles, make.createFileList(classgen_src_dir, ".*\\.java",
		(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)));
		
classFiles = make.substitute("(.*)\\.java", build_dir+"/$1.class", sourceFiles);


//-------------------------------------------------------------------
//==-- CREATE LIST OF CLASS FILES TO BUILD --==
compileList = "";
compileCnt = 0;
make.createPatternRule(build_dir+"/(.*).class", "$1.java", "removeClass", false);
removeClass(String target, String[] prereqs)
	{
	//print(prereqs[0]);  //Prints the files that will be built
	rm(target);
	compileList += prereqs[0]+" ";
	compileCnt ++;
	}
	
//-------------------------------------------------------------------
//==-- COMPILE CLASS FILES --==
make.createPhonyRule("compile", build_dir+" "+make.arrayToString(classFiles), "compile");
compile(String target, String[] prereqs)
	{
	print("Compiling "+compileCnt+" source files");
	cmd = "javac -g -classpath "+classpath+" -d "+build_dir+
			" -sourcepath "+src_dir+" "+compileList;
	make.exec(cmd, true);
	}

//-------------------------------------------------------------------
//==-- JAVADOC RULE --==
make.createPhonyRule("makejavadoc", javadoc_dir, "createJavaDoc");
createJavaDoc(String target, String[] prereqs)
	{
	ps = make.getProperty("path.separator");
	cmd = "javadoc -d "+javadoc_dir+" -sourcepath "+src_dir+ps+classgen_src_dir+
			"-version -author -use -windowtitle BeanShell -doctitle <h1>BeanShell</h1> "+
			"-bottom <em>&#169;&nbsp;2000&nbsp;[email protected]&nbsp;:-)</em> -quiet "+
			"bsh bsh.util bsh.classpath bsh.reflect";
	make.exec(cmd);
	}
	
//-------------------------------------------------------------------
//==-- COPY RULES --==
make.createCopyRule("copyCommands", null, src_dir+"/bsh/commands",
		".*\\.bsh", build_dir+"/bsh/commands");
make.createCopyRule("copyLibs", null, src_dir+"/bsh/util/lib", 
		".*", build_dir+"/bsh/util/lib");
make.createCopyRule("copyServlet", null, src_dir+"/bsh/servlet", 
		"(.*\\.bsh)|(.*\\.template)", build_dir+"/bsh/servlet");
				
//-------------------------------------------------------------------
//==-- GENERAL JAR CREATE METHOD --==
createJar(String jarFile, String srcDir, String[] fileList, String manifest)
	{
	print("Creating "+jarFile);
	fileList = make.substitute("(.++)", "-C "+srcDir+" $1", fileList);
	if (manifest == null)
		cmd = "jar -cf "+jarFile+" "+make.arrayToString(fileList);
	else
		cmd = "jar -cfm "+jarFile+" "+manifest+" "+make.arrayToString(fileList);
	make.exec(cmd);
	}
	
//-------------------------------------------------------------------
//==-- GENERAL WAR CREATE METHOD --==
createWar(String warFile, String file, String webxml, String lib)
	{
	print("Creating "+warFile);
	if (lib == null)
		make.mkdir("temp/WEB-INF");
	else
		{
		make.mkdir("temp/WEB-INF/lib");
		make.copy(lib, "temp/WEB-INF/lib");
		}
	
	make.copy(file, "temp/");
		
	make.copy(webxml, "temp/WEB-INF/web.xml");
	
	cmd = "jar -cf "+warFile+" -C temp .";
	make.exec(cmd);
	
	make.deltree("temp");
	}
	
//-------------------------------------------------------------------
//==-- ALL JAR FILE --==
make.createPhonyRule("jarall", all_jar, null);
make.createExplicitRule(all_jar, "compile copyCommands copyLibs copyServlet "+
		dist_dir, "createAllJar", true);
createAllJar(String target, String[] prereqs)
	{
	createJar(all_jar, build_dir, make.createFileList(build_dir, "bsh/(.*)", 
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), 
			src_dir+"/Manifest.console");
	}

//-------------------------------------------------------------------
//==-- CORE JAR FILE --==	
make.createPhonyRule("jarcore", core_jar, null);
make.createExplicitRule(core_jar, "compile "+dist_dir, "createCoreJar", true);
createCoreJar(String target, String[] prereqs)
	{
	createJar(core_jar, build_dir, make.createFileList(build_dir, "(bsh/[^/]*\\.class)",
			"(bsh/Console.class)|(bsh/Remote.*)|(bsh/ClassGeneratorImpl.*)|"+
			"(bsh/ClassGeneratorUtil.*)|(bsh/DelayedEvalBshMethod.*)", 
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), 
			src_dir+"/Manifest.interp");
	}

//-------------------------------------------------------------------
//==-- SOURCE JAR FILE --==
srcJarList = make.createFileList(".", "(.*)",
			"(.*CVS.*)|(classes.*)|(dist.*)|(.*javadoc.*)|(.*\\.jar)|(.*\\.war)"+
			"|(.*\\.cvs.*)|(.cpmakecache)", 
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH));
make.createPhonyRule("jarsrc", src_jar, null);
make.createExplicitRule(src_jar, make.arrayToString(srcJarList)+dist_dir, "createSrcJar", true);
createSrcJar(String target, String[] prereqs)
	{
	srcJarList = make.substitute("(.++)", "BeanShell/$1", srcJarList);
	createJar(src_jar, "..", srcJarList, src_dir+"/Manifest.interp");
	}
	
//-------------------------------------------------------------------
//==-- COMMANDS JAR FILE --==
make.createExplicitRule(commands_jar, dist_dir+" compile", "createCommandsJar", true);
createCommandsJar(String target, String[] prereqs)
	{
	createJar(commands_jar, build_dir, make.createFileList(build_dir, 
			"(bsh/commands/((.*\\.class)|(.*\\.bsh)))",
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), null);
	}

//-------------------------------------------------------------------
//==-- CLASSPATH JAR FILE --==
make.createExplicitRule(classpath_jar, dist_dir+" compile", "createClasspathJar", true);
createClasspathJar(String target, String[] prereqs)
	{
	createJar(classpath_jar, build_dir, make.createFileList(build_dir, 
			"(bsh/classpath/.*\\.class)",
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), null);
	}
	
//-------------------------------------------------------------------
//==-- REFLECT JAR FILE --==
make.createExplicitRule(reflect_jar, dist_dir+" compile", "createReflectJar", true);
createReflectJar(String target, String[] prereqs)
	{
	createJar(reflect_jar, build_dir, make.createFileList(build_dir, 
			"(bsh/reflect/.*\\.class)",
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), null);
	}
	
//-------------------------------------------------------------------
//==-- UTIL JAR FILE --==
make.createExplicitRule(util_jar, dist_dir+" compile", "createUtilJar", true);
createUtilJar(String target, String[] prereqs)
	{
	createJar(util_jar, build_dir, make.createFileList(build_dir, 
			"(bsh/util/.*)", "(bsh/util/BeanShellBSFEngine.class)",
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)), null);
	}
	
//-------------------------------------------------------------------
//==-- BSF JAR FILE --==
make.createExplicitRule(bsf_jar, dist_dir+" compile", "createBsfJar", true);
createBsfJar(String target, String[] prereqs)
	{
	createJar(bsf_jar, build_dir, new String[] {"bsh/util/BeanShellBSFEngine.class"}, null);
	}
	
//-------------------------------------------------------------------
//==-- CLASSGEN JAR FILE --==
make.createExplicitRule(classgen_jar, dist_dir+" compile", "createClassgenJar", true);
createClassgenJar(String target, String[] prereqs)
	{
	classgenFileList = make.createFileList(build_dir,
			"(bsh/ClassGeneratorImpl.*\\.class)|(bsh/ClassGeneratorUtil.*\\.class)|"+
			"(bsh/DelayedEvalBshMethod.*\\.class)", 
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH));
	classgenFileList = make.combine(classgenFileList, make.createFileList(build_dir,
			"bsh/org/objectweb/asm.*\\.class",
			(make.INCLUDE_PATH | make.RECURSE | make.RELATIVE_PATH)));
	createJar(classgen_jar, build_dir, classgenFileList, null);
	}

//-------------------------------------------------------------------
//==-- JAVADOC JAR FILE --==
make.createExplicitRule(javadoc_jar, dist_dir+" makejavadoc", "createJavadocJar", true);
createJavadocJar(String target, String[] prereqs)
	{
	cmd = "jar -cf "+javadoc_jar+" -C "+javadoc_dir+" .";
	make.exec(cmd);
	}
	
//-------------------------------------------------------------------
//==-- SERVLET WBSH JAR FILE --==
make.createExplicitRule(bshservlet_wbsh_war, dist_dir+" compile", "createWbshServletWar", true);
createWbshServletWar(String target, String[] prereqs)
	{
	createWar(bshservlet_wbsh_war, src_dir+"/bsh/servlet/index.html",
			src_dir+"/bsh/servlet/example-web.xml", all_jar); 
	}

//-------------------------------------------------------------------
//==-- SERVLET JAR FILE --==
make.createExplicitRule(bshservlet_war, dist_dir+" compile", "createServletWar", true);
createServletWar(String target, String[] prereqs)
	{
	createWar(bshservlet_war, src_dir+"/bsh/servlet/index.html",
			src_dir+"/bsh/servlet/example-web.xml", null); 
	}
	
//-------------------------------------------------------------------
//==-- BSH DOC --==
bshDocDepFiles = make.arrayToString(make.createFileList("src/bsh/commands", ".*\\.bsh",
			(make.INCLUDE_PATH | make.RECURSE)));
make.createExplicitRule(commands_bshdoc, bshDocDepFiles+all_jar, "createBshDoc", true);
createBshDoc(String target, String[] prereqs)
	{
	print("Creating "+target);
	cmd = "java -classpath "+all_jar+" bsh.Interpreter scripts/bshdoc.bsh "+
			bshDocDepFiles;
			
	make.exec(null, cmd, true, null, commands_bshdoc);
	}
	
//-------------------------------------------------------------------
//==-- DISTRIBUTION RULE --==
make.createPhonyRule("distribute", new String[] {
		core_jar,
		all_jar,
		src_jar,
		commands_jar,
		classpath_jar,
		reflect_jar,
		util_jar,
		bsf_jar,
		classgen_jar,
		javadoc_jar,
		bshservlet_wbsh_war,
		bshservlet_war,
		commands_bshdoc }, null);

//-------------------------------------------------------------------
//==-- RUN SCRIPT --==
make.createPhonyRule("bsh", "compile", "runScript");
runScript(String target, String[] prereqs)
	{
	file = make.getProperty("file");
	ps = make.getProperty("path.sererator");
	if (file == null)
		{
		print("Please specify a script file with \"-D file=script.bsh\" on the command line");
		return;
		}
	cmd = "java -classpath "+classpath+ps+build_dir+" bsh.Interpreter "+file;
	make.exec(cmd);
	}

//-------------------------------------------------------------------
//==-- RUN TEST SUITE --==
make.createPhonyRule("test", all_jar, "test");
test(String target, String[] prereqs)
	{
	make.setProperty("file", "tests/RunAllTests.bsh");
	runScript(null, null);
	}
	
//-------------------------------------------------------------------
//==-- CLEAN RULE --==
//Can't use autoclean because it will remove Parser.java
make.createPhonyRule("clean", null, "clean");
clean(String target, String[] prereqs)
	{
	print("Removing "+build_dir);
	make.deltree(build_dir);
	print("Removing "+dist_dir);
	make.deltree(dist_dir);
	print("Removing "+javadoc_dir);
	make.deltree(javadoc_dir);
	}
	

//If the build file changes everything must be rebuilt
//make.createPatternDependency("(.*\\.class)|(.*\\.jar)", "build.bsh");
	
make.setDefaultTarget(all_jar);