Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New erjang.Main, now runs as "java -jar erjang.jar"

  • Loading branch information...
commit 5c098d33d35cdac4d444832b7deddc81d7e565fa 1 parent a420f3a
@krestenkrab krestenkrab authored
View
7 OTP.launch
@@ -2,7 +2,7 @@
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<stringAttribute key="bad_container_name" value="\erlang\o"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/erlang/src/main/java/erjang/OTPMain.java"/>
+<listEntry value="/erlang/src/main/java/erjang/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
@@ -11,8 +11,7 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="erjang.OTPMain"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-root ${env_var:OTPROOT}&#13;&#10;-progname erl&#13;&#10;--&#13;&#10;-home ${env_var:HOME}"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="erjang.Main"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-root ${env_var:ERLROOT}"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="erlang"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Derj.threads=1&#13;&#10;-Derjpath=${env_var:OTP_ERTS_EBIN}"/>
</launchConfiguration>
View
2  build.xml
@@ -99,7 +99,7 @@
<exclude name="erjang/examples/**" />
<exclude name="erjang/bench/**" />
<manifest>
- <attribute name="Main-Class" value="erjang.Erj" />
+ <attribute name="Main-Class" value="erjang.Main" />
</manifest>
</jar>
</target>
View
8 erl.cmd
@@ -2,11 +2,7 @@
IF "x%OTPROOT%" == "x" SET OTPROOT="C:/Program Files/erl5.7.5"
-java -ea -cp erjang-0.1.jar ^
- -Derj.threads=1 ^
- -Derjpath=%OTP_ERTS_EBIN% erjang.OTPMain ^
+java -cp erjang-0.1.jar ^
+ erjang.Main ^
-root %OTPROOT% ^
- -progname erl ^
- -- ^
- -home %HOME% ^
%1 %2 %3 %4 %5 %6 %7 %8 %9
View
9 erl.sh
@@ -1,16 +1,11 @@
#!/bin/bash
if [ "x${OTPROOT}" == "x" ]; then
- OTPROOT=/sw/lib/erlang
+ OTPROOT=/sw/lib/erlang
fi
-java -server -ea -cp erjang-0.1.jar \
- -Derj.threads=2 \
- -Derjpath=$OTPROOT/lib/erts-5.7.3/ebin erjang.OTPMain \
+java -server -jar erjang-0.1.jar \
-root $OTPROOT \
- -progname erl \
- -- \
- -home $HOME \
$*
View
158 src/main/java/erjang/Main.java
@@ -0,0 +1,158 @@
+/**
+ * This file is part of Erjang - A JVM-based Erlang VM
+ *
+ * Copyright (c) 2009 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.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class Main {
+
+ static String erts_version = "erts-5.7.3";
+ static String erl_rootdir;
+ static String erl_bootstrap_ebindir;
+
+ static String setup(String cmd_line_root) {
+
+ erl_rootdir = cmd_line_root;
+ if (cmd_line_root == null)
+ erl_rootdir = System.getenv("OTPROOT");
+
+ if (erl_rootdir == null) {
+ erl_rootdir = guess_erl_root();
+ }
+
+ erl_bootstrap_ebindir = System.getenv("ERL_BOOTSTRAP_EBIN");
+ if (erl_bootstrap_ebindir == null) {
+ erl_bootstrap_ebindir = erl_rootdir + File.separator + "lib" + File.separator
+ + erts_version + File.separator + "ebin";
+ }
+
+ return erl_rootdir;
+ }
+
+ private static String guess_erl_root() {
+
+ // this logic works on Unixes ... what about windows?
+ String path = System.getenv("PATH");
+ for (String elem : path.split(File.pathSeparator)) {
+ File dir = new File(elem);
+ File erl = new File(dir, "erl");
+ if (erl.exists()) {
+
+ if (dir.getParent() == null)
+ continue;
+
+ File lib = new File (dir.getParent(), "lib");
+ File root = new File(lib, "erlang");
+
+ if (root.exists()) {
+ return root.getAbsolutePath();
+ }
+
+ }
+ }
+
+ System.err.println("Cannot find OTPROOT directory\n"
+ + "Pass -root <dir>, or set environment variable.");
+ System.exit(-1);
+
+ return null;
+ }
+
+ /**
+ * @param args
+ * @throws IOException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws ClassNotFoundException
+ */
+ public static void main(String[] args)
+ throws Exception {
+
+ ArrayList<String> ra = new ArrayList<String>();
+
+ String cmd_line_root = null;
+ for (int i = 0; i < args.length; i++) {
+ if ("-root".equals(args[i]) && i < args.length) {
+ cmd_line_root = args[i+1];
+ i +=1;
+ } else if ("+e".equals(args[i]) && i < args.length) {
+ erts_version = "erts-" + args[i+1];
+ i += 1;
+ }
+ }
+
+ String root = setup(cmd_line_root);
+
+ if (cmd_line_root == null) {
+ ra.add("-root");
+ ra.add(root);
+ }
+
+ arg_loop:
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i];
+
+ if ("-extra".equals(arg)) {
+ for (int ii = i; ii < args.length; ii++) {
+ ra.add(args[ii]);
+ }
+ break;
+ }
+
+ if (arg.charAt(0) == '+') {
+ switch (arg.charAt(1)) {
+ case 'a':
+ case 'e': // strip erts version too
+ case 'A':
+ case 'B':
+ case 'h':
+ case 'K':
+ case 'M':
+ case 'P':
+ case 'R':
+ case 'S':
+ case 's':
+ case 't':
+ case 'T':
+ case 'W':
+ System.setProperty("erjang.beam.option."+arg, args[i+1]);
+ i += 1;
+ continue arg_loop;
+ default:
+ System.setProperty("erjang.beam.option."+arg, "true");
+ continue arg_loop;
+ }
+ }
+
+ ra.add(arg);
+ }
+
+ System.setProperty("erjpath", erl_bootstrap_ebindir);
+
+ if (!(new File(erl_bootstrap_ebindir)).exists()) {
+ System.err.println("No bootstrap classes at: "+erl_bootstrap_ebindir);
+ return;
+ }
+
+ OTPMain.main(ra.toArray(new String[ra.size()]));
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.