Permalink
Browse files

working on sbt 0.11 build

  • Loading branch information...
1 parent 8c713ab commit ff0719e6cb63a6c6da2e41ed6eda11c794051666 @SethTisue SethTisue committed May 10, 2012
View
@@ -38,8 +38,6 @@ tmp/
/docs/infotab.html
/lib/
/out/
-/project/boot/
-/project/plugins/project/
/resources/Errors_??.properties
/resources/GUI_Strings_??.properties
/resources/system/dict.txt
View
@@ -1,31 +1,68 @@
#!/bin/sh
-LAUNCH=`dirname $0`/sbt-launch-0.11.2.jar
-URL='http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar'
-
-if [ ! -f $LAUNCH ] ; then
- curl -f $URL -o $LAUNCH || exit
-fi
-
-if [ `uname -s` = Linux ] ; then
- export JAVA_HOME=/usr/lib/jvm/java-1.6.0-sun-1.6.0.31
+if [[ `uname -s` == *CYGWIN* ]] ; then
+ CURR_DIR="$( cd "$( dirname "$0" )" && pwd )"
+ export JAVA_HOME=`cygpath -up "\Java\jdk1.6.0_31"`
else
- if [ `uname -s` = Darwin ] ; then
- export JAVA_HOME=`/usr/libexec/java_home -F -v1.5+`
+ CURR_DIR=`dirname $0`
+ if [ `uname -s` = Linux ] ; then
+ export JAVA_HOME=/usr/lib/jvm/java-6-sun
else
- export JAVA_HOME=/usr
+ if [ `uname -s` = Darwin ] ; then
+ export JAVA_HOME=`/usr/libexec/java_home -F -v1.6+`
+ else
+ export JAVA_HOME=/usr
+ fi
fi
fi
export PATH=$JAVA_HOME/bin:$PATH
JAVA=$JAVA_HOME/bin/java
+TOOLS=$JAVA_HOME/lib/tools.jar
+
+# Most of these settings are fine for everyone
+XSS=-Xss2m
+XMX=-Xmx1536m
+XX=-XX:MaxPermSize=256m
+ENCODING=-Dfile.encoding=UTF-8
+HEADLESS=-Djava.awt.headless=true
+USE_QUARTZ=-Dapple.awt.graphics.UseQuartz=false
+COLON=:
+BOOT=xsbt.boot.Boot
+
+# Windows/Cygwin users need these settings
+if [[ `uname -s` == *CYGWIN* ]] ; then
+
+ # While you might want the max heap size lower, you'll run out
+ # of heap space from running the tests if you don't crank it up
+ # (namely, from TestChecksums)
+ XMX=-Xmx1350m
+ TOOLS=`cygpath -w $TOOLS`
+ SBT_LAUNCH=`cygpath -w $SBT_LAUNCH`
+ COLON=\;
+
+ # This gets SBT working properly in my heavily-modded version of Cygwin --JAB (2/7/2012)
+ if [ "$TERM" = "xterm" ] ; then
+ TERMINAL=-Djline.terminal=jline.UnixTerminal
+ fi
+
+fi
+
+SBT_LAUNCH=`dirname $0`/sbt-launch-0.11.3.jar
+URL='http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.11.3/sbt-launch.jar'
+
+if [ ! -f $SBT_LAUNCH ] ; then
+ curl -f $URL -o $SBT_LAUNCH || exit
+fi
+# UseQuartz=false so that we get pixel for pixel identical drawings between OS's, so TestChecksums works - ST 6/9/10
+# add tools.jar to the classpath so we can use native2ascii on linux - ST 1/7/11
$JAVA \
- -Xss2m -Xmx1536m -XX:MaxPermSize=256m \
- -Djava.library.path= \
- -Djava.ext.dirs= \
- -Dfile.encoding=UTF-8 \
- -Dapple.awt.graphics.UseQuartz=false \
- $JAVA_OPTS \
- -classpath $LAUNCH \
- xsbt.boot.Boot "$@"
+ $XSS $XMX $XX \
+ $ENCODING \
+ $JAVA_OPTS \
+ $HEADLESS \
+ $TERMINAL \
+ $USE_QUARTZ \
+ -classpath $TOOLS$COLON$SBT_LAUNCH \
+ $BOOT "$@"
View
@@ -22,21 +22,22 @@ javaSource in Test <<= baseDirectory(_ / "src" / "test")
resolvers += "java.net" at "http://download.java.net/maven/2"
-libraryDependencies ++= Seq("asm" % "asm-all" % "3.3.1",
- "org.picocontainer" % "picocontainer" % "2.13.6",
- "log4j" % "log4j" % "1.2.16",
- "javax.media" % "jmf" % "2.1.1e",
- "org.pegdown" % "pegdown" % "1.1.0",
- "org.parboiled" % "parboiled-java" % "1.0.2",
- "steveroy" % "mrjadapter" % "1.2" from "http://ccl.northwestern.edu/devel/mrjadapter-1.2.jar",
- "org.jhotdraw" % "jhotdraw" % "6.0b1" from "http://ccl.northwestern.edu/devel/jhotdraw-6.0b1.jar",
- "ch.randelshofer" % "quaqua" % "7.3.4" from "http://ccl.northwestern.edu/devel/quaqua-7.3.4.jar",
- "ch.randelshofer" % "swing-layout" % "7.3.4" from "http://ccl.northwestern.edu/devel/swing-layout-7.3.4.jar",
- "org.jogl" % "jogl" % "1.1.1" from "http://ccl.northwestern.edu/devel/jogl-1.1.1.jar",
- "org.gluegen-rt" % "gluegen-rt" % "1.1.1" from "http://ccl.northwestern.edu/devel/gluegen-rt-1.1.1.jar",
- "org.jmock" % "jmock" % "2.5.1" % "test",
- "org.jmock" % "jmock-legacy" % "2.5.1" % "test",
- "org.jmock" % "jmock-junit4" % "2.5.1" % "test",
- "org.scalacheck" % "scalacheck_2.9.1" % "1.9" % "test",
- "org.scalatest" %% "scalatest" % "1.8.RC1" % "test")
-
+libraryDependencies ++= Seq(
+ "asm" % "asm-all" % "3.3.1",
+ "org.picocontainer" % "picocontainer" % "2.13.6",
+ "log4j" % "log4j" % "1.2.16",
+ "javax.media" % "jmf" % "2.1.1e",
+ "org.pegdown" % "pegdown" % "1.1.0",
+ "org.parboiled" % "parboiled-java" % "1.0.2",
+ "steveroy" % "mrjadapter" % "1.2" from "http://ccl.northwestern.edu/devel/mrjadapter-1.2.jar",
+ "org.jhotdraw" % "jhotdraw" % "6.0b1" from "http://ccl.northwestern.edu/devel/jhotdraw-6.0b1.jar",
+ "ch.randelshofer" % "quaqua" % "7.3.4" from "http://ccl.northwestern.edu/devel/quaqua-7.3.4.jar",
+ "ch.randelshofer" % "swing-layout" % "7.3.4" from "http://ccl.northwestern.edu/devel/swing-layout-7.3.4.jar",
+ "org.jogl" % "jogl" % "1.1.1" from "http://ccl.northwestern.edu/devel/jogl-1.1.1.jar",
+ "org.gluegen-rt" % "gluegen-rt" % "1.1.1" from "http://ccl.northwestern.edu/devel/gluegen-rt-1.1.1.jar",
+ "org.jmock" % "jmock" % "2.5.1" % "test",
+ "org.jmock" % "jmock-legacy" % "2.5.1" % "test",
+ "org.jmock" % "jmock-junit4" % "2.5.1" % "test",
+ "org.scalacheck" % "scalacheck_2.9.1" % "1.9" % "test",
+ "org.scalatest" %% "scalatest" % "1.8.RC1" % "test"
+)
View
@@ -0,0 +1,84 @@
+import java.io.File
+import sbt._
+
+object Autogen {
+
+ def events(log: String => Unit, base: File, dir: File, ppackage: String): File = {
+ val file = dir / "org" / "nlogo" / ppackage / "Events.java"
+ log("creating: " + file)
+
+ var codeString = ""
+ def append(s: String) = codeString += (s + "\n")
+
+ val (access, qualify) = ppackage match {
+ case "window" => ("public ", "")
+ case "app" => ("", "org.nlogo.window.")
+ }
+
+ append(IO.read(base / "project" / "autogen" / "warning.txt"))
+
+ append("package org.nlogo." + ppackage + " ;")
+ append("\n")
+ append(access + "final strictfp class Events")
+ append("{")
+ append(" // not instantiable")
+ append(" private Events() { throw new IllegalStateException() ; }")
+ append("\n")
+
+ for{line <- IO.read(base /"project" / "autogen" / "events.txt").split("\n")
+ if !line.trim.isEmpty // skip blank lines
+ if !line.startsWith("#") // skip comment lines
+ if line.startsWith(ppackage)} // skip unless in right package
+ {
+ val splitt = line.split("-").filter(!_.isEmpty)
+ val shortName = splitt(0).split('.')(1).trim
+ val fieldString = splitt.drop(1).mkString("-")
+
+ val name = shortName + "Event"
+ append(" " + access + "static strictfp class " + name + " extends " + qualify + "Event")
+ append(" {")
+ val fields = fieldString.split(""" \s*-\s* """).filter(!_.isEmpty).map(_.trim)
+ if (!fields.isEmpty) {
+ for (field <- fields)
+ append(" " + access + "final " + field + " ;")
+ append(" " + access + name + fields.mkString("( ", " , ", " )"))
+ append(" {")
+ for (field <- fields) {
+ val variable = field.split("""\s+""").drop(1)(0)
+ append(" this." + variable + " = " + variable + " ;")
+ }
+ append(" }")
+ }
+ append(" @Override public void beHandledBy( " + qualify + "Event.Handler handler )")
+ append(" {")
+ append(" ( (Handler) handler ).handle( this ) ;")
+ append(" }")
+ append(" " + access + "interface Handler extends " + qualify + "Event.Handler")
+ append(" {")
+ append(" void handle( " + name + " e ) ;")
+ append(" }")
+ append(" }")
+ }
+ append("}")
+
+ IO.write(file, codeString)
+ file
+ }
+
+ // this used to be broken into two tasks, but jflex doesnt seem to be threadsafe
+ // so we have to run them serially, which means we have to generate them both each time. -JC 6/8/10
+ def flex(log: String => Unit, base: File, dir: File, ppackage: String, kind: String): File = {
+ val autogenFolder = base / "project" / "autogen"
+ log("creating autogen/" + kind + ".java")
+ JFlex.Main.main(Array("--quiet", (autogenFolder / (kind + ".flex")).asFile.toString))
+ log("creating src/main/org/nlogo/" + ppackage + "/" + kind + ".java")
+ val nlogoPackage = dir / "org" / "nlogo"
+ val result = nlogoPackage / ppackage / (kind + ".java")
+ IO.write(result,
+ IO.read(autogenFolder / "warning.txt") +
+ IO.read(autogenFolder / (kind + ".java")))
+ (autogenFolder / (kind + ".java")).asFile.delete()
+ result
+ }
+
+}
View
@@ -0,0 +1,18 @@
+import sbt._
+import Keys._
+
+object NetLogoBuild extends Build {
+ lazy val root =
+ Project(
+ id = "NetLogo",
+ base = file("."),
+ settings = Defaults.defaultSettings ++ Seq(
+ sourceGenerators in Compile <+=
+ (javaSource in Compile, baseDirectory, streams) map {
+ (dir, base, s) =>
+ Seq(Autogen.events(s.log.info(_), base, dir, "window"),
+ Autogen.events(s.log.info(_), base, dir, "app"),
+ Autogen.flex(s.log.info(_), base, dir, "agent", "ImportLexer"),
+ Autogen.flex(s.log.info(_), base, dir, "lex", "TokenLexer"))}
+ ))
+}
@@ -0,0 +1,121 @@
+// -*- Java -*- (tell Emacs to use Java mode)
+
+package org.nlogo.agent ;
+
+// Since this is automatically generated code it's not surprising
+// it'd produce a few warnings - ST 3/6/08
+@SuppressWarnings({"unused","fallthrough"})
+
+%%
+
+/* this option decreases code size; see JFlex documentation */
+%switch
+
+%unicode
+
+%yylexthrow{
+ ImportLexer.LexerException
+%yylexthrow}
+
+%{
+ static String[] lex( String source )
+ throws LexerException
+ {
+ ImportLexer yy = new ImportLexer( new java.io.StringReader( source + "," ) ) ;
+ java.util.List<String> result = new java.util.ArrayList<String>() ;
+ try
+ {
+ while( true )
+ {
+ String s = yy.yylex() ;
+ if( s == null )
+ {
+ break ;
+ }
+ result.add( s ) ;
+ }
+ }
+ // we should never get one of these since we're using StringReaders,
+ // but the Yylex stuff uses generic BufferedReaders, so we have to
+ // declare that we handle this exception
+ catch( java.io.IOException ex )
+ {
+ throw new IllegalStateException( ex ) ;
+ }
+ return result.toArray( new String[ result.size() ] ) ;
+ }
+
+ static class LexerException
+ extends Exception
+ {
+ public LexerException( String details )
+ {
+ super( details ) ;
+ }
+ }
+
+ private static String unescape( String s )
+ {
+ if( s.indexOf( "\"\"" ) == -1 )
+ {
+ return s ;
+ }
+ StringBuilder result = new StringBuilder() ;
+ for( int i = 0 ; i < s.length() ; i++ )
+ {
+ char c = s.charAt( i ) ;
+ if( c == '"' && i < s.length() - 1 && s.charAt( i + 1 ) == '"' )
+ {
+ result.append( '"' ) ;
+ i++ ;
+ }
+ else
+ {
+ result.append( c ) ;
+ }
+ }
+ return result.toString() ;
+ }
+%}
+
+%class ImportLexer
+%type String
+%state COMMA,QUOTED
+
+NORMAL=[^,\"]
+SPACE=[\ \t\b\012]
+STRING_CONTENTS=([^\"]|\"\")
+
+%%
+
+<YYINITIAL> {
+ , { return "" ; }
+ {NORMAL}+ {
+ yybegin( COMMA ) ;
+ return yytext().trim() ;
+ }
+ {SPACE}*\" { yybegin( QUOTED ) ; }
+}
+
+<COMMA> {
+ , { yybegin( YYINITIAL ) ; }
+ . {
+ throw new ImportLexer.LexerException
+ ( "Quoted fields must be followed by comma or end of line" ) ;
+ }
+}
+
+<QUOTED> {
+ \"{SPACE}* {
+ yybegin( COMMA ) ;
+ return "" ;
+ }
+ {STRING_CONTENTS}+\"{SPACE}* {
+ yybegin( COMMA ) ;
+ String text = yytext() ;
+ return unescape( text.substring( 0 , text.lastIndexOf( '"' ) ) ) ;
+ }
+ . {
+ throw new ImportLexer.LexerException( "Unclosed double quote" ) ;
+ }
+}
Oops, something went wrong.

0 comments on commit ff0719e

Please sign in to comment.