Permalink
Browse files

created a jar that compiles CoffeeScript using mozilla rhino for coff…

…eescript 0.6.1.
  • Loading branch information...
1 parent 091da10 commit 1dbe0f4655e2e42febac66c9d66911fb8e3583e5 @yeungda committed May 5, 2010
View
@@ -2,6 +2,14 @@
<project version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
+ <buildFile url="file://$PROJECT_DIR$/build.xml">
+ <additionalClassPath />
+ <antReference projectDefault="true" />
+ <customJdkName value="" />
+ <maximumHeapSize value="128" />
+ <maximumStackSize value="2" />
+ <properties />
+ </buildFile>
</component>
</project>
View
@@ -17,6 +17,7 @@
<entry name="?*.dtd" />
<entry name="?*.tld" />
<entry name="?*.ftl" />
+ <entry name="?*.js" />
</wildcardResourcePatterns>
<annotationProcessing enabled="false" useClasspath="true" />
</component>
View
@@ -0,0 +1,11 @@
+<component name="libraryTable">
+ <library name="Rhino">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/lib/js.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$PROJECT_DIR$/lib/js-src.zip!/src" />
+ </SOURCES>
+ </library>
+</component>
View
@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
- <module fileurl="file://$PROJECT_DIR$/coffeescript-rhino.iml" filepath="$PROJECT_DIR$/coffeescript-rhino.iml" />
+ <module fileurl="file://$PROJECT_DIR$/jcoffeescript.iml" filepath="$PROJECT_DIR$/jcoffeescript.iml" />
</modules>
</component>
</project>
View
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2010 David Yeung
+ ~
+ ~ 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.
+ -->
+
+<project name="JCoffeeScript" default="build">
+
+ <target name="build" depends="bootstrap, clean, functional-test"/>
+
+ <property name="artifact.name" value="jcoffeescript-0.1"/>
+ <import file="${basedir}/conf/build/build-bootstrap.xml"/>
+ <import file="${basedir}/conf/build/build-clean.xml"/>
+ <import file="${basedir}/conf/build/build-compile.xml"/>
+ <import file="${basedir}/conf/build/build-test.xml"/>
+ <import file="${basedir}/conf/build/build-jar.xml"/>
+
+ <target name="dependencies">
+ <path id="compile.classpath">
+ <fileset dir="${basedir}/lib">
+ <include name="js.jar"/>
+ </fileset>
+ </path>
+ <path id="test.classpath">
+ <path refid="compile.classpath"/>
+ <fileset dir="${basedir}/lib">
+ <include name="hamcrest-all-1.3RC0.jar"/>
+ <include name="junit-dep-4.8.2.jar"/>
+ </fileset>
+ </path>
+ </target>
+
+ <target name="functional-test" depends="jar">
+ <java inputstring="a:1" jar="${basedir}/target/dist/${artifact.name}.jar" failonerror="true" fork="true"/>
+ </target>
+</project>
Submodule coffee-script deleted from 1cddb2
Binary file not shown.
@@ -0,0 +1,7 @@
+<project>
+
+ <target name="bootstrap">
+ <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/conf/build/bootstrap/ant-contrib-1.0b3.jar"/>
+ </target>
+
+</project>
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+
+ <target name="clean" description="cleans target folder">
+ <delete dir="${basedir}/target" includeEmptyDirs="true" failonerror="true" />
+ </target>
+
+</project>
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>
+
+ <target name="dependencies">
+ <fail message="[dependencies] target should be defined outside the scope of build-compile"/>
+ </target>
+
+ <target name="compile" depends="dependencies, compile-all" description="compile all source folders"/>
+
+ <target name="compile-all">
+ <compile-folder folder="main" classpathref="compile.classpath"/>
+ <compile-folder folder="standalone" classpathref="test.classpath"/>
+ <compile-folder folder="unit-tests" classpathref="test.classpath"/>
+ <compile-folder folder="integration-tests" classpathref="test.classpath"/>
+ </target>
+
+ <macrodef name="compile-folder">
+ <attribute name="folder" />
+ <attribute name="classpathref" />
+ <sequential>
+ <if>
+ <available file="${basedir}/src/@{folder}/java" type="dir"/>
+ <then>
+ <mkdir dir="${basedir}/target/classes/@{folder}"/>
+ <javac srcdir="${basedir}/src/@{folder}/java" destdir="${basedir}/target/classes/@{folder}" source="1.5" target="1.5" debug="true">
+ <classpath>
+ <path refid="@{classpathref}"/>
+ <pathelement location="${basedir}/target/classes/main" />
+ </classpath>
+ </javac>
+ <copy todir="${basedir}/target/classes/@{folder}">
+ <fileset dir="${basedir}/src/@{folder}/java" excludes="**/*.java"/>
+ </copy>
+ </then>
+ </if>
+ <if>
+ <available file="${basedir}/src/@{folder}/resources" type="dir"/>
+ <then>
+ <mkdir dir="${basedir}/target/classes/@{folder}" />
+ <copy todir="${basedir}/target/classes/@{folder}">
+ <fileset dir="${basedir}/src/@{folder}/resources" />
+ </copy>
+ </then>
+ </if>
+ </sequential>
+ </macrodef>
+
+</project>
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+ <target name="jar" depends="test">
+ <mkdir dir="${basedir}/target/dist"/>
+ <pathtofileset name="jars" pathrefid="compile.classpath" dir="${basedir}/lib"/>
+
+ <jar destfile="${basedir}/target/dist/${artifact.name}.jar">
+ <manifest><attribute name="Main-Class" value="org.jcoffeescript.Main"/></manifest>
+ <zipgroupfileset refid="jars"/>
+ <metainf dir="${basedir}/.." includes="LICENSE,NOTICE"/>
+ <zipfileset dir="${basedir}/target/classes/main"/>
+ </jar>
+ </target>
+</project>
View
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+
+ <target name="compile">
+ <fail message="[compile] target should be defined outside the scope of build-test"/>
+ </target>
+
+ <target name="test" depends="compile">
+ <sequential>
+ <run-test folder="unit-tests" />
+ <run-test folder="integration-tests" />
+ <fail if="tests-failed" message="tests failed" />
+ </sequential>
+ </target>
+
+ <macrodef name="run-test">
+ <attribute name="folder" />
+ <sequential>
+ <if>
+ <available file="${basedir}/src/@{folder}/java" type="dir"/>
+ <then>
+ <delete dir="${basedir}/target/test-reports/@{folder}" includeEmptyDirs="true" failonerror="true" />
+ <mkdir dir="${basedir}/target/test-reports/@{folder}" />
+ <mkdir dir="${basedir}/target/test-reports/@{folder}/xml" />
+ <mkdir dir="${basedir}/target/test-reports/@{folder}/html" />
+ <junit printsummary="yes" fork="yes" forkmode="once" failureproperty="tests-failed">
+ <classpath>
+ <path refid="test.classpath" />
+ <pathelement location="${basedir}/target/classes/main" />
+ <pathelement location="${basedir}/target/classes/@{folder}" />
+ </classpath>
+ <formatter type="xml" />
+ <batchtest fork="yes" todir="${basedir}/target/test-reports/@{folder}/xml">
+ <fileset dir="${basedir}/target/classes/@{folder}" includes="**/*Test.class" />
+ </batchtest>
+ </junit>
+ <junitreport todir="${basedir}/target/test-reports/@{folder}/html">
+ <fileset dir="${basedir}/target/test-reports/@{folder}/xml">
+ <include name="TEST-*.xml"/>
+ </fileset>
+ <report format="frames" todir="${basedir}/target/test-reports/@{folder}/html"/>
+ </junitreport>
+ </then>
+ </if>
+ </sequential>
+ </macrodef>
+
+</project>
@@ -4,8 +4,8 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/test" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/coffee-script/lib" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -18,15 +18,6 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/lib/junit/4.8.2/junit-dep-4.8.2.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
@@ -36,28 +27,11 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="library" name="Rhino" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
- <root url="jar://$MODULE_DIR$/narwhal/engines/rhino/jars/js.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/narwhal/engines/rhino/jars/jline.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES />
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root url="jar://$MODULE_DIR$/narwhal/engines/rhino/jars/jna.jar!/" />
+ <root url="jar://$MODULE_DIR$/lib/junit-dep-4.8.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
View
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Submodule narwhal deleted from e88dd6
@@ -1,64 +0,0 @@
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.Script;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
-import org.mozilla.javascript.tools.shell.Main;
-
-import java.io.FileReader;
-import java.io.IOException;
-
-public class CoffeeScriptRunner {
- public static void main(String[] args) {
- final Context context = Context.enter();
- context.setOptimizationLevel(-1);
- final ScriptableObject theGlobal = context.initStandardObjects();
-
- final Object[] objects = {"/Users/dyeung/Projects/coffeescript-rhino/narwhal/engines/rhino/bin/narwhal-rhino", "-o", "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/test.js", "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/hello.coffee"};
- final ScriptableObject scriptableObject = context.initStandardObjects(theGlobal, false);
- final Scriptable argumentsArray = context.newArray(theGlobal, objects);
- theGlobal.defineProperty("arguments", argumentsArray, ScriptableObject.DONTENUM);
- String source = readFile("/Users/dyeung/Projects/coffeescript-rhino/narwhal/engines/rhino/bootstrap.js");
- final Script globals = Main.loadScriptFromSource(context, "NARWHAL_HOME='/Users/dyeung/Projects/coffeescript-rhino/narwhal'", "<cmd>", 1, null);
- Object o = Main.evaluateScript(globals, context, scriptableObject);
-
- final Script script = Main.loadScriptFromSource(context, source, "<cmd>", 1, null);
- o = Main.evaluateScript(script, context, scriptableObject);
- System.out.println("scriptableObject.toString() = " + scriptableObject.get("js"));
- }
-
- private static class CoffeeScriptRhinoOnlyRunner {
- public static void main(String[] args) {
- final Context context = Context.enter();
- final ScriptableObject theGlobal = context.initStandardObjects();
- final ScriptableObject scriptableObject = context.initStandardObjects(theGlobal, false);
- final Script globals = Main.loadScriptFromSource(context, "function require () {return {}}; window={}", "<cmd>", 1, null);
- Object o = Main.evaluateScript(globals, context, scriptableObject);
-
- evaluate(context, scriptableObject, "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/helpers.js");
- evaluate(context, scriptableObject, "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/nodes.js");
- evaluate(context, scriptableObject, "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/lexer.js");
- evaluate(context, scriptableObject, "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/parser.js");
- evaluate(context, scriptableObject, "/Users/dyeung/Projects/coffeescript-rhino/coffee-script/lib/coffee-script.js");
- System.out.println("scriptableObject.toString() = " + scriptableObject.get("js"));
- }
-
- private static void evaluate(Context context, ScriptableObject scriptableObject, String fileName) {
- Object o;
- String source = readFile(fileName);
- final Script script = Main.loadScriptFromSource(context, source, "<cmd>", 1, null);
- o = Main.evaluateScript(script, context, scriptableObject);
- }
- }
- private static String readFile(String fileName) {
- final StringBuffer buffer = new StringBuffer();
- try {
- final FileReader fileReader = new FileReader(fileName);
- while (fileReader.ready()) {
- buffer.append((char) fileReader.read());
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return buffer.toString();
- }
-}
Oops, something went wrong.

0 comments on commit 1dbe0f4

Please sign in to comment.