Permalink
Browse files

Environment (and other) configuration has been reworked; Erjang now u…

…ses approximately the same root config in normal and test mode.

Also, cleaned up test code a bit and changed "testwoven" target to use the JUnit Ant task.
  • Loading branch information...
1 parent 495f9d3 commit f88abd94947cc4d678ae66cbd7b64091d2e582f9 Erik Søe Sørensen committed Nov 27, 2010
View
@@ -87,13 +87,13 @@
<!-- This runs those tests depend on generated classes in testclasses-->
<target name="testwoven">
<echo message="Testing Tasks ======================" />
- <java classname="junit.textui.TestRunner" fork="yes">
+ <junit fork="yes" showoutput="yes">
+ <formatter type="xml"/>
<classpath refid="erjang.testwovenclasspath" />
- <assertions>
- <enable />
- </assertions>
- <arg value="erjang.AllTests" />
- </java>
+ <assertions><enable /></assertions>
+ <jvmarg value="-Derjang.configfile=env_cfg.properties" />
+ <test name="erjang.AllTests" />
+ </junit>
</target>
<target name="jar" description="generate the distribution" depends="clean,weave">
View
22 ej
@@ -3,27 +3,27 @@
## Script to run the ERLConsole
##
-EJC_CMD=`which "$0"`
-while LINK=`readlink "$EJC_CMD"`; do EJC_CMD=$LINK; done
-EJC_DIR=`dirname "$EJC_CMD"`
+EJ_CMD=`which "$0"`
+while LINK=`readlink "$EJ_CMD"`; do EJ_CMD=$LINK; done
+ERJANG_DIR=`dirname "$EJ_CMD"`
-source $EJC_DIR/env_cfg
+source "$ERJANG_DIR/env_cfg"
-## -Derjang.debug.port=true
-## -Derjang.debug.inet=true
## -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
-
exec java \
-server \
-Xmx1g -Xss50m \
-XX:PermSize=128m \
- -jar $EJC_DIR/erjang-0.1.jar \
+ -Derjang.configfile="$PROP_FILE" \
+ -Derjang.erts.version="$ERTS_VSN" \
+ -Derjang.otp.version="$OTP_VSN" \
+ -jar $ERJANG_DIR/erjang-0.1.jar \
\
-progname ej \
- -home $HOME \
- -root $ERL_ROOT \
+ -home "$HOME" \
+ -root "$ERL_ROOT" \
+A 10 \
+S 1 \
- +e $ERTS_VSN \
+ +e "$ERTS_VSN" \
"$@"
View
22 ejc
@@ -5,21 +5,33 @@
EJC_CMD=`which "$0"`
while LINK=`readlink "$EJC_CMD"`; do EJC_CMD=$LINK; done
-EJC_DIR=`dirname "$EJC_CMD"`
+ERJANG_DIR=`dirname "$EJC_CMD"`
-source $EJC_DIR/env_cfg
+source "$ERJANG_DIR/env_cfg"
+###########################################################
+# OS X - specific config
+if [[ $(uname) == "Darwin" ]]; then
+ OSX_DOCK_ICON="-Xdock:icon=$ERJANG_DIR/erjang_logo4.png"
+ OSX_DOCK_NAME="-Xdock:name=ErjangConsole"
+fi
+###########################################################
+
+# (TODO: OSX_DOCK variable expansions should expand into only one token - or zero, on non-OSX platforms.)
exec java \
-server \
-Xss1m \
-Xmx2g \
$OSX_DOCK_ICON \
$OSX_DOCK_NAME \
- -cp $EJC_DIR/erjang-0.1.jar erjang.console.ERLConsole \
+ -Derjang.configfile="$PROP_FILE" \
+ -Derjang.erts.version="$ERTS_VSN" \
+ -Derjang.otp.version="$OTP_VSN" \
+ -cp "$ERJANG_DIR/erjang-0.1.jar" erjang.console.ERLConsole \
+\
-root "$ERL_ROOT" \
+A 10 \
+S 1 \
+e "$ERTS_VSN" \
-home "$HOME" \
- $*
-
+ "$@"
View
35 env_cfg
@@ -1,16 +1,29 @@
-# set the defaults if there is no environment variable
+# Read and/or guess Erjang settings
+PROP_FILE="$ERJANG_DIR/erjang_cfg.properties"
+if [ -r "$PROP_FILE" ] ; then
+ shopt -s extglob # Used for trimming
+ # Parse properties file:
+ while s=""; read s || [ -n "$s" ] ; do
+ if [[ "$s" == "#"* ]] ; then continue; fi # Comment line
+ if [[ "$s" != *"="* ]] ; then continue; fi # No '='
+ propname=${s%%=*} ; propname=${propname%%*([[:space:]])}
+ propvalue=${s#*=} ; propvalue=${propvalue##*([[:space:]])}
-if [[ -z ${ERTS_VSN} ]]; then
- ERTS_VSN=5.8
-fi
-if [[ -z ${ERL_ROOT} ]]; then
- ERL_ROOT=/Users/krab/Projects/otp-5.8
+ # Set variable if it has the right prefix:
+ if [[ "$propname" == "erjang."* ]] ; then
+ varname=${propname//./_}
+ declare "$varname"="$propvalue"
+ fi
+ done < "$PROP_FILE"
fi
-###########################################################
+## For listing parsed property names:
+# echo "${!erjang*}"
-# OS X - specific config
-if [[ $(uname) == "Darwin" ]]; then
- OSX_DOCK_ICON="-Xdock:icon=$EJC_DIR/erjang_logo4.png"
- OSX_DOCK_NAME="-Xdock:name=ErjangConsole"
+ERL_ROOT=${erjang_otp_root:-/usr/lib/erlang}
+if [ -r "$ERL_ROOT/releases/start_erl.data" ] ; then
+ ERTS_VSN_GUESS=$(awk '{print $1}' "$ERL_ROOT/releases/start_erl.data")
+ OTP_VSN_GUESS=$(awk '{print $2}' "$ERL_ROOT/releases/start_erl.data")
fi
+ERTS_VSN=${erjang_erts_version:-$ERTS_VSN_GUESS}
+OTP_VSN=${erjang_otp_version:-$OTP_VSN_GUESS}
View
@@ -0,0 +1,7 @@
+erjang.otp.root = /usr/local/lib/erlang
+# erjang.erts.version = 5.8
+# erjang.otp.version = R14A
+
+# erjang.debug.port=true
+# erjang.debug.inet=true
+# erjang.dump_on_exit = true
@@ -68,7 +68,7 @@ public static EModule load_module(String moduleName, File beamFile) throws IOExc
static long acc_load = 0;
public static EModule load_module(String moduleName, EBinary beamBin) throws IOException {
// This is where the module creation mode is selected.
- boolean use_interpreter = Boolean.getBoolean("erjang.beam.option.i");
+ boolean use_interpreter = ErjangConfig.getBoolean("erjang.beam.option.i");
long before = System.currentTimeMillis();
long after;
@@ -121,7 +121,7 @@ private static File findBeamFile(String module) {
if (sys_path != null)
addLoadPaths(loadPath, sys_path);
- String path = System.getProperty("erjpath", ".");
+ String path = ErjangConfig.getString("erjang.path", ".");
addLoadPaths(loadPath, path);
}
@@ -765,7 +765,7 @@ public static EInternalPID find(int id, int serial) {
static {
- if (Boolean.getBoolean("erj.dump_on_exit"))
+ if (ErjangConfig.getBoolean("erjang.dump_on_exit"))
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
@@ -293,8 +293,8 @@ public static EAtom guard(boolean bool) {
public static final boolean DEBUG = false;
public static final boolean DEBUG2 = false;
public static final boolean DEBUG_WAIT = false;
- public static final boolean DEBUG_PORT = Boolean.getBoolean("erjang.debug.port");
- public static final boolean DEBUG_INET = Boolean.getBoolean("erjang.debug.inet");
+ public static final boolean DEBUG_PORT = ErjangConfig.getBoolean("erjang.debug.port");
+ public static final boolean DEBUG_INET = ErjangConfig.getBoolean("erjang.debug.inet");
public static final boolean DEBUG_EFILE = false;
public static final EBinary EMPTY_BINARY = new EBinary(new byte[0]);
public static final ByteBuffer[] EMPTY_BYTEBUFFER_ARR = new ByteBuffer[0];
@@ -1009,15 +1009,15 @@ public void execute() throws Pausable, Exception {
* @return
*/
public static int threadPoolSize() {
- String threads = System.getProperty("erjang.beam.option.S");
+ String threads = ErjangConfig.getString("erjang.beam.option.S");
if (threads != null)
return Integer.parseInt(threads);
else
return Runtime.getRuntime().availableProcessors();
}
public static int asyncThreadPoolSize() {
- String threads = System.getProperty("erjang.beam.option.A");
+ String threads = ErjangConfig.getString("erjang.beam.option.A");
if (threads != null)
return Integer.parseInt(threads);
else
@@ -0,0 +1,76 @@
+/**
+ * This file is part of Erjang - A JVM-based Erlang VM
+ *
+ * Copyright (c) 2010 by Trifork
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
+package erjang;
+
+import java.util.Properties;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+/**
+ * Reads a configuration file at system startup, and provides access to
+ * the settings therein.
+ * The configuration file is a Java 'properties' file (as defined by
+ * java.util.Properties), and its location is defined by the
+ * Java property "erjang.configfile".
+ */
+public class ErjangConfig {
+
+ static {
+ String configFileName = System.getProperty("erjang.configfile");
+ if (configFileName != null) {
+ try {
+ FileInputStream in = new FileInputStream(configFileName);
+ try {
+ Properties properties = new Properties();
+ properties.load(in);
+ for (String name : properties.stringPropertyNames()) {
+ if (name.startsWith("erjang.") && System.getProperty(name)==null) { // Don't overwrite e.g. properties given on the command line
+ System.setProperty(name, properties.getProperty(name));
+ }
+ }
+ } finally {
+ in.close();
+ }
+ } catch (IOException ioe) {
+ System.err.println("Failed to load Erjang properties from "+configFileName+": "+ioe);
+ }
+ }
+ }
+
+ public static void init() {}
+
+ /*==================== Getters ========================================
+ * Like System.getProperty() and e.g. Boolean.getBoolean(), but
+ * ensures that initialization of this class is performed first:
+ */
+ public static boolean getBoolean(String propname) {
+ return Boolean.getBoolean(propname);
+ }
+
+ public static int getInteger(String propname) {
+ return Integer.getInteger(propname);
+ }
+
+ public static String getString(String propname) {
+ return System.getProperty(propname);
+ }
+ public static String getString(String propname, String fallback) {
+ return System.getProperty(propname, fallback);
+ }
+}
@@ -24,10 +24,10 @@
public class Main {
public static final String SYSTEM_ARCHITECTURE = "java";
- public static final String OTP_VERSION = "R14A";
+ public static final String OTP_VERSION = ErjangConfig.getString("erjang.otp.version", "R14A");
public static final String DRIVER_VERSION = "1.5";
- static String erts_version = "erts-5.7.3";
+ static String erts_version = "erts-"+ErjangConfig.getString("erjang.erts.version", "5.8");
static String erl_rootdir;
static String erl_bootstrap_ebindir;
@@ -90,8 +90,8 @@ private static String guess_erl_root() {
* @throws InstantiationException
* @throws ClassNotFoundException
*/
- public static void main(String[] args)
- throws Exception {
+ public static void main(String[] args) throws Exception {
+ ErjangConfig.init();
ArrayList<String> ra = new ArrayList<String>();
@@ -152,7 +152,7 @@ public static void main(String[] args)
ra.add(arg);
}
- System.setProperty("erjpath", erl_bootstrap_ebindir);
+ System.setProperty("erjang.path", erl_bootstrap_ebindir);
if (!(new File(erl_bootstrap_ebindir)).exists()) {
System.err.println("No bootstrap classes at: "+erl_bootstrap_ebindir);
@@ -29,7 +29,7 @@
*/
public class AllTests {
- static final String OTP_HOME = "/Users/krab/Projects/otp";
+ static final String OTP_HOME = ErjangConfig.getString("erjang.otp.root");
public static Test suite() {
TestSuite suite = new TestSuite("Test for erjang");
@@ -47,9 +47,9 @@
*/
public class TestRunFile implements Test {
- static final String OTP_HOME = "/Users/krab/Projects/otp";
- static final String ERLC_PRG = "/sw/bin/erlc";
- static final String ERL_PRG = "/sw/bin/erl";
+ static final String OTP_HOME = ErjangConfig.getString("erjang.otp.root");
+ static final String ERLC_PRG = OTP_HOME + File.separator + "bin" + File.separator + "erlc";
+ static final String ERL_PRG = OTP_HOME + File.separator + "bin" + File.separator + "erl";
static final EAtom ERJANG_ATOM = EAtom.intern("erjang");
static final EAtom ERLANG_ATOM = EAtom.intern("erlang");
@@ -70,8 +70,11 @@
public TestRunFile(File file) {
this.file = file;
- System.setProperty("erjpath", OTP_HOME + "/erts/preloaded/ebin"
- + ":" + OTP_HOME + "/lib/stdlib/ebin");
+ String path1 = OTP_HOME + File.separator + "erts" + File.separator
+ + "preloaded" + File.separator + "ebin";
+ String path2 = OTP_HOME + File.separator + "lib" + File.separator
+ + "stdlib" + File.separator + "ebin";
+ System.setProperty("erjang.path", path1 + File.pathSeparator + path2);
}

0 comments on commit f88abd9

Please sign in to comment.