// project.beh -- project management in DemeterJ. // $Id: project.beh,v 1.16 2002/02/23 00:13:15 dougo Exp $ Project { (@ static final String fileExtension = ".prj"; @) } { Project, ProjectName } { /** The file corresponding to the project. */ File file() to ProjectName { before ProjectName (@ return_val = new File(host + Project.fileExtension); @) } } Project { /** Print a sample project file to out. */ void printSampleFile(PrintWriter out, boolean withInput) (@ String nl = Line.nl; out.println( "// " + file() + " -- DemeterJ project file" + nl +"// Generated by DemeterJ version " + Main.version + nl +"" + nl +"// NOTE: This file may contain path names or other platform-dependent" + nl +"// information. You may need to edit them when moving from one" + nl +"// platform to another." + nl +"" + nl +"// The class dictionary file." + nl +"CDFILE = " + name + ".cd" + nl +"" + nl +"// Dirs containing plain java files to compile along with generated code." + nl +"// NB: Dir structure must match packages for dependency calculation to work." + nl +"JAVADIRS = " + nl +"" + nl +"// The cool files." + nl +"BEHFILES = " + name + ".beh" + nl +"" + nl +"// The cool files." + nl +"COOLFILES = "+nl// + name + ".cool" + nl +"" + nl +"// The ridl files." + nl +"RIDLFILES = "+ nl +"" + nl +"// The name of the class which has the \"main\" method." + nl +"MAIN = Main" + nl +"" + nl +"// The package your generated code belongs to. It should match" + nl +"// the package specified at the beginning of your .cd file." + nl +"PACKAGE =" + nl +"" + nl +"// Code generator arguments." + nl +"GENERATE_ARGS = -tracevis -displayvis -printvis -copyvis -equalvis" + nl +"" + nl +"// The directory into which .java files are generated." + nl +"GENDIR = gen" + nl +"" + nl +"// The parser generator executable." + nl +"PARSEGEN = javacc" + (System.getProperty("os.name").startsWith("Windows") ? ".bat" : "") + nl +"" + nl +"// Parser generator arguments." + nl +"PARSEGEN_ARGS = " + nl +"" + nl +"// The Java compiler executable." + nl +"COMPILER = javac" + nl +"" + nl +"// Java compiler arguments." + nl +"COMPILE_ARGS = -g -deprecation" + nl +"" + nl +"// Java classpath to be passed to the COMPILER. Whatever you "+nl +"// put here comes after CLASSDIR:GENDIR, but before $CLASSPATH."+nl +"CLASSPATH = "+nl +"" + nl +"// The directory into which .class files are generated." + nl +"CLASSDIR = " + new File("gen", "classes") + nl +"" + nl //+"// The jarfile in which to package all the .class files." + nl //+"JARFILE = " + new File("gen", name + ".jar") + nl //+"" + nl +"// The Java virtual machine executable." + nl +"JVM = java" + nl +"" + nl +"// The virtual machine option for setting the class path." + nl +"CLASSPATH_OPTION = -classpath" + nl +"" + nl +"// Arguments for testing the program." + nl +"TEST_ARGS =" + nl +"" + nl +"// Input file for testing the program." + nl +"TEST_INPUT =" + (withInput ? " " + name + ".input" : "") + nl +"" + nl +"// Files and directories to be removed when cleaning up." + nl +"CLEAN_ARGS = gen" + nl //+"CLEAN_ARGS = $(GENDIR) $(CLASSDIR) $(JARFILE) *~" + nl ); out.flush(); @) /** Get an option with the given string name, or null if it isn't set. */ OptionValue getOption(String s) (@ return getOption(OptionName.parse(s)); @) /** Get an option with the given name, or null if it isn't set. */ OptionValue getOption(OptionName name) to { OptionName, OptionValue } { (@ OptionName n; OptionValue v; @) before OptionName (@ n = host; @) before OptionValue (@ v = host; @) after OptionSetting (@ if (n.equals(name)) return_val = v; @) } /** Get a one-word option with the given name, or null if it isn't set. */ String getWordOption(String name) (@ OptionValue val = getOption(name); return val == null ? null : val.toString().trim(); @) /** Get a one-word option with the given name, or dflt if it isn't set or is set to the empty string. */ String getWordOption(String name, String dflt) (@ OptionValue val = getOption(name); if (val == null) return dflt; String ret = val.toString().trim(); return ret.length() == 0 ? dflt : ret; @) /** Get a whole-line option with the given name, or null if it isn't set or is set to empty string. */ String getLineOption(String name) (@ OptionValue val = getOption(name); if (val == null) return null; String ret = val.toString().trim(); return ret.length() == 0 ? null : ret; @) /** Get an option as an enumeration of words, or null if it isn't set. */ Enumeration getWordsOption(String name) (@ OptionValue val = getOption(name); return val == null ? null : val.words(); @) /** Get a file option with the given name, or dflt if it isn't set. */ File getFileOption(String name, File dflt) (@ OptionValue val = getOption(name); return val == null ? dflt : new File(val.toString().trim()); @) /** Get an option as an enumeration of files, or convert dflt into an enumeration of files if the option isn't set. */ Enumeration getFilesOption(String name, String dflt) (@ OptionValue val = getOption(name); return val == null ? new FileEnumeration(dflt) : val.files(); @) /** Get the list of module-specific arguments, or null if not set. */ Enumeration getModuleArgs(Module module) (@ return getWordsOption(module + "_ARGS"); @) /** Get the directory into which Java files are generated. Defaults to "gen", relative to the current directory. */ File getGenDir() (@ return getFileOption("GENDIR", new File("gen")); @) /** Get the directory into which class files are generated. Defaults to "classes", relative to the value of getGenDir(). */ File getClassDir() (@ return getFileOption("CLASSDIR", new File(getGenDir(), "classes")); @) /** Get the class dictionary file. Defaults to the project name with ".cd" appended. */ File getCDFile() (@ return getFileOption("CDFILE", new File(this.get_name() + ".cd")); @) /** Get the list of behavior files. Defaults to the project name with ".beh" appended. */ Enumeration getBehFiles() (@ return getFilesOption("BEHFILES", this.get_name() + ".beh"); @) /** Get the list of cool files. Defaults to the empty list, as if we don't specify a cool file, we probly don't want cool. */ Enumeration getCoolFiles() (@ return getFilesOption("COOLFILES", ""); @) /** Get the list of ridl files. Defaults to the empty list, as if we don't specify a ridl file, we probly don't want ridl. */ Enumeration getRidlFiles() (@ return getFilesOption("RIDLFILES", ""); @) /** Get a list of directories that should be searched for java files to be compiled in the context of the rest of the application */ Enumeration getJavaFileDirs() (@ return getFilesOption("JAVADIRS", ""); @) /** Get the jar file. Defaults to the project name with ".jar" appended, in the generated directory. */ File getJarFile() (@ return getFileOption("JARFILE", new File(this.getGenDir(), this.get_name() + ".jar")); @) /** Get the name of the parser generator executable. Defaults to "javacc". */ String getParseGen() (@ return getWordOption("PARSEGEN", "javacc"); @) /** Get the name of the Java compiler executable. Defaults to "javac". */ String getCompiler() (@ return getWordOption("COMPILER", "javac"); @) /** Get the name of the main class. Defaults to "Main". */ String getMainClass() (@ return getWordOption("MAIN", "Main"); @) /** Get the package name. Defaults to null, i.e. no package. */ String getPackage() (@ return getWordOption("PACKAGE", null); @) /** Get a bunch of classpath entries, ending with a File.Separator. Defaults to the empty string. */ String getClassPath() (@ String words = getLineOption("CLASSPATH"); return (words == null ? "" : words + File.pathSeparator); @) /** Get the name of the Java virtual machine executable. Defaults to "java". */ String getJVM() (@ return getWordOption("JVM", "java"); @) /** Get the option used by the virtual machine to specify the class path. Defaults to "-classpath". */ String getClasspathOption() (@ return getWordOption("CLASSPATH_OPTION", "-classpath"); @) /** Get the test input file. Defaults to null, i.e. use stdin. */ File getTestInputFile() (@ File file = getFileOption("TEST_INPUT", null); return (file == null || file.toString().length() == 0) ? null : file; @) } OptionName { /** Ignore case when comparing option names. */ public boolean equals(Object n) (@ return n instanceof OptionName && (n.toString().equalsIgnoreCase(toString())); @) /** Ignore case (by converting to lower) for computing the hash value. */ public int hashCode() (@ return toString().toLowerCase().hashCode(); @) } OptionValue { /** Split the option into words. */ Enumeration words() (@ return new WordEnumeration(toString().trim()); @) /** Split the option into files. */ Enumeration files() (@ return new FileEnumeration(toString().trim()); @) } WordEnumeration { (@ WordEnumeration(String s) { super(s); } @) init (@ this(""); @) public Object nextElement() (@ return (String) super.nextElement(); @) } FileEnumeration { (@ FileEnumeration(String s) { super(s); } @) init (@ this(""); @) public Object nextElement() (@ return new File((String) super.nextElement()); @) }