Merge pull request #7 from blalor/repackage_for_jar

Repackage for JAR
This commit is contained in:
jefklak 2012-11-24 06:36:02 -08:00
commit 56fba96f71
67 changed files with 17421 additions and 17376 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ eclipsecompiled
.classpath
.project
.settings
*.iml
.idea

0
bin/bootstrap.js vendored Executable file → Normal file
View File

0
bin/js.jar Executable file → Normal file
View File

0
bin/rhino.bat Executable file → Normal file
View File

0
bin/rhino.debug.bat Executable file → Normal file
View File

0
jasmine-junit-runner.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

7
pom.xml Executable file → Normal file
View File

@ -11,9 +11,9 @@
<dependencies>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.7R2</version>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7R4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -60,6 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>

View File

View File

0
src/main/java/be/klak/junit/jasmine/JasmineSpec.java Executable file → Normal file
View File

View File

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
class JasmineSpecRunnerGenerator {
@ -66,12 +67,17 @@ class JasmineSpecRunnerGenerator {
}
private String loadTemplate() {
String template = null;
try {
template = FileUtils.readFileToString(new File(suite.jsRootDir() + "/lib/specRunner.tpl"));
return IOUtils.toString(
Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream("js/lib/specRunner.tpl")
);
} catch (NullPointerException e) {
throw new IllegalStateException("spec runner template file not found!");
} catch (IOException e) {
throw new RuntimeException("spec runner template file not found!", e);
}
return template;
throw new IllegalStateException("spec runner template file could not be read!", e);
}
}
}

0
src/main/java/be/klak/junit/jasmine/JasmineSuite.java Executable file → Normal file
View File

View File

@ -4,6 +4,9 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.apache.commons.lang.StringUtils;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.Description;
@ -18,7 +21,9 @@ import be.klak.rhino.RhinoContext;
public class JasmineTestRunner extends Runner {
private static final int SLEEP_TIME_MILISECONDS = 50;
private static final String JASMINE_LIB_DIR = "/lib/jasmine-1.0.2/";
// relative to classpath
private static final String JASMINE_LIB_DIR = "js/lib/jasmine-1.0.2";
private JasmineDescriptions jasmineSuite;
@ -67,8 +72,8 @@ public class JasmineTestRunner extends Runner {
protected void pre(RhinoContext context) { }
private void setUpJasmine(RhinoContext context) {
context.load(getJsLibDir() + "jasmine.js");
context.load(getJsLibDir() + "jasmine.delegator_reporter.js");
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.js");
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.delegator_reporter.js");
context.evalJS("jasmine.getEnv().addReporter(new jasmine.DelegatorJUnitReporter());");
}
@ -106,11 +111,26 @@ public class JasmineTestRunner extends Runner {
}
private void resetEnvjsWindowSpace() {
this.rhinoContext.evalJS("window.location = '" + suiteAnnotation.jsRootDir() + "/lib/blank.html';");
URL blankUrl = Thread
.currentThread()
.getContextClassLoader()
.getResource("js/lib/blank.html");
if (blankUrl == null) {
throw new IllegalStateException("Unable to load js/lib/blank.html from classpath");
}
private String getJsLibDir() {
return suiteAnnotation.jsRootDir() + JASMINE_LIB_DIR;
String blankUrlStr = blankUrl.toExternalForm();
// "file:/path/to/file" is not legal, but "file:///path/to/file" is
if (blankUrlStr.startsWith("file:/") && (! blankUrlStr.startsWith("file:///"))) {
blankUrlStr = "file://" + blankUrlStr.substring(5);
}
this.rhinoContext.evalJS(String.format(
"window.location = '%s';",
blankUrlStr
));
}
private JasmineDescriptions getJasmineDescriptions() {

0
src/main/java/be/klak/rhino/ChainedErrorReporter.java Executable file → Normal file
View File

29
src/main/java/be/klak/rhino/RhinoContext.java Executable file → Normal file
View File

@ -1,5 +1,7 @@
package be.klak.rhino;
import java.net.URL;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Function;
@ -86,6 +88,24 @@ public class RhinoContext {
// Main.processFile(this.jsContext, this.jsScope, fileName);
}
// {{{ loadFromClasspath
/**
* Loads a resource from the classpath.
*
* @param resource the resource to resolve from the classpath
*/
public void loadFromClasspath(final String resource) {
URL rsrcUrl =
Thread.currentThread().getContextClassLoader().getResource(resource);
if (rsrcUrl == null) {
throw new IllegalArgumentException("resource " + resource + " not found on classpath");
}
evalJS(String.format("load('%s')", rsrcUrl.toExternalForm()));
}
// }}}
public Object executeFunction(ScriptableObject object, String fnName, Object[] arguments) {
Object fnPointer = object.get(fnName, object);
if (fnPointer == null || !(fnPointer instanceof Function)) {
@ -108,11 +128,8 @@ public class RhinoContext {
}
public void loadEnv(String jsDir) {
// TODO ensure rhino 1.7R3 instead of R2 -> geen shim nodig + paths
// gedoe in orde zetten hier
load(jsDir + "/lib/es5-shim-0.0.4.min.js");
load(jsDir + "/lib/env.rhino.1.2.js");
load(jsDir + "/lib/env.utils.js");
loadFromClasspath("js/lib/env.rhino.1.2.js");
loadFromClasspath("js/lib/env.utils.js");
load(jsDir + "/envJsOptions.js");
}
@ -125,7 +142,7 @@ public class RhinoContext {
private Context createJavascriptContext() {
Context jsContext = ContextFactory.getGlobal().enterContext();
jsContext.setOptimizationLevel(-1);
jsContext.setLanguageVersion(Context.VERSION_1_5); // TODO 1.8 plx
jsContext.setLanguageVersion(Context.VERSION_1_8);
jsContext.setErrorReporter(new ChainedErrorReporter(jsContext.getErrorReporter()));
return jsContext;
}

0
src/main/java/be/klak/rhino/RhinoRunnable.java Executable file → Normal file
View File

View File

@ -1093,7 +1093,7 @@ Envjs.uri = function(path, base) {
}
// if path is absolute, then just normalize and return
if (path.match('^[a-zA-Z]+://')) {
if (path.match('^([a-zA-Z]+://|jar:file:/)')) {
return urlparse.urlnormalize(path);
}
@ -1499,7 +1499,7 @@ Envjs.connection = function(xhr, responseHandler, data){
instream,
responseXML,
i;
if ( /^file\:/.test(url) ) {
if ( /^(jar:)?file\:/.test(url) ) {
try{
if ( "PUT" == xhr.method || "POST" == xhr.method ) {
data = data || "" ;

View File

@ -1,4 +1,3 @@
/**
* Rhino and Envjs additions, filling the missing pieces such as a decent stacktrace
* 1) Firefox knows new Error().stack but Envjs does not.
@ -140,7 +139,7 @@
* also sets clearTimeout & clearInterval on same level.
*/
(function() {
var threadTimeoutPool = {};
var threadTimeoutPool = new java.util.HashMap();
window.setTimeout = function(closure, timeout) {
var thread = spawn(function() {
@ -155,7 +154,7 @@
}
});
threadTimeoutPool[thread.getId()] = thread;
threadTimeoutPool.put(thread.getId(), thread);
return thread.getId();
};
@ -174,15 +173,14 @@
}
});
threadTimeoutPool[thread.getId()] = thread;
threadTimeoutPool.put(thread.getId(), thread);
return thread.getId();
};
window.clearTimeout = function(threadId) {
if (threadId) {
if(threadTimeoutPool[threadId]) {
threadTimeoutPool[threadId].interrupt();
delete threadTimeoutPool[threadId];
if(threadTimeoutPool.containsKey(threadId)) {
threadTimeoutPool.remove(threadId).interrupt();
}
}
};

2
src/test/java/be/klak/env/EnvUtilsTest.java vendored Executable file → Normal file
View File

@ -13,7 +13,7 @@ public class EnvUtilsTest {
@Before
public void loadJasmineJQueryMatchers(RhinoContext context) {
context.load("src/test/javascript/lib/jasmine-1.0.2/jasmine-jquery-rhino.js");
context.loadFromClasspath("js/lib/jasmine-1.0.2/jasmine-jquery-rhino.js");
}
}

View File

View File

0
src/test/java/be/klak/rhino/ClassInJS.java Executable file → Normal file
View File

View File

View File

10
src/test/java/be/klak/rhino/RhinoContextTest.java Executable file → Normal file
View File

@ -80,4 +80,14 @@ public class RhinoContextTest {
assertThat(context.evalJS("loaded")).isEqualTo(true);
assertThat(context.evalJS("loadedTwo")).isEqualTo(true);
}
// {{{ loadsJSFilesFromClasspath
@Test
public void loadsJSFilesFromClasspath() {
RhinoContext context = new RhinoContext();
context.loadFromClasspath("js/lib/loadsJSFilesFromClasspathTarget.js");
assertThat(context.evalJS("target.theAnswer")).isEqualTo("forty two");
}
// }}}
}

0
src/test/javascript/envJsOptions.js Executable file → Normal file
View File

0
src/test/javascript/jquery-1.6.1.js vendored Executable file → Normal file
View File

View File

@ -1,13 +0,0 @@
(function(){var j=Object.prototype.hasOwnProperty;if(!Array.isArray)Array.isArray=function(a){return Object.prototype.toString.call(a)=="[object Array]"};if(!Array.prototype.forEach)Array.prototype.forEach=function(a,c){for(var b=this.length>>>0,d=0;d<b;d++)d in this&&a.call(c,this[d],d,this)};if(!Array.prototype.map)Array.prototype.map=function(a,c){var b=this.length>>>0;if(typeof a!="function")throw new TypeError;for(var d=Array(b),e=0;e<b;e++)if(e in this)d[e]=a.call(c,this[e],e,this);return d};
if(!Array.prototype.filter)Array.prototype.filter=function(a,c){for(var b=[],d=0;d<this.length;d++)a.call(c,this[d])&&b.push(this[d]);return b};if(!Array.prototype.every)Array.prototype.every=function(a,c){for(var b=0;b<this.length;b++)if(!a.call(c,this[b]))return false;return true};if(!Array.prototype.some)Array.prototype.some=function(a,c){for(var b=0;b<this.length;b++)if(a.call(c,this[b]))return true;return false};if(!Array.prototype.reduce)Array.prototype.reduce=function(a){var c=this.length>>>
0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var b=0;if(arguments.length>=2)var d=arguments[1];else{do{if(b in this){d=this[b++];break}if(++b>=c)throw new TypeError;}while(1)}for(;b<c;b++)if(b in this)d=a.call(null,d,this[b],b,this);return d};if(!Array.prototype.reduceRight)Array.prototype.reduceRight=function(a){var c=this.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;c=c-1;if(arguments.length>=
2)var b=arguments[1];else{do{if(c in this){b=this[c--];break}if(--c<0)throw new TypeError;}while(1)}for(;c>=0;c--)if(c in this)b=a.call(null,b,this[c],c,this);return b};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a,c){var b=this.length;if(!b)return-1;var d=c||0;if(d>=b)return-1;if(d<0)d+=b;for(;d<b;d++)if(j.call(this,d))if(a===this[d])return d;return-1};if(!Array.prototype.lastIndexOf)Array.prototype.lastIndexOf=function(a,c){var b=this.length;if(!b)return-1;var d=c||b;if(d<0)d+=
b;for(d=Math.min(d,b-1);d>=0;d--)if(j.call(this,d))if(a===this[d])return d;return-1};if(!Object.getPrototypeOf)Object.getPrototypeOf=function(a){return a.__proto__||a.constructor.prototype};if(!Object.getOwnPropertyDescriptor)Object.getOwnPropertyDescriptor=function(){return{}};if(!Object.getOwnPropertyNames)Object.getOwnPropertyNames=function(a){return Object.keys(a)};if(!Object.create)Object.create=function(a,c){var b;if(a===null)b={__proto__:null};else{if(typeof a!="object")throw new TypeError("typeof prototype["+
typeof a+"] != 'object'");b=function(){};b.prototype=a;b=new b}typeof c!=="undefined"&&Object.defineProperties(b,c);return b};if(!Object.defineProperty)Object.defineProperty=function(a,c,b){if(typeof b=="object"&&a.__defineGetter__){if(j.call(b,"value")){if(!a.__lookupGetter__(c)&&!a.__lookupSetter__(c))a[c]=b.value;if(j.call(b,"get")||j.call(b,"set"))throw new TypeError("Object doesn't support this action");}else typeof b.get=="function"&&a.__defineGetter__(c,b.get);typeof b.set=="function"&&a.__defineSetter__(c,
b.set)}return a};if(!Object.defineProperties)Object.defineProperties=function(a,c){for(var b in c)j.call(c,b)&&Object.defineProperty(a,b,c[b]);return a};if(!Object.seal)Object.seal=function(a){return a};if(!Object.freeze)Object.freeze=function(a){return a};try{Object.freeze(function(){})}catch(u){Object.freeze=function(a){return function(c){return typeof c=="function"?c:a(c)}}(Object.freeze)}if(!Object.preventExtensions)Object.preventExtensions=function(a){return a};if(!Object.isSealed)Object.isSealed=
function(){return false};if(!Object.isFrozen)Object.isFrozen=function(){return false};if(!Object.isExtensible)Object.isExtensible=function(){return true};if(!Object.keys){var m=true,n=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],p=n.length,q;for(q in{toString:null})m=false;Object.keys=function(a){if(typeof a!=="object"&&typeof a!=="function"||a===null)throw new TypeError("Object.keys called on a non-object");var c=[],b;for(b in a)j.call(a,
b)&&c.push(b);if(m)for(b=0;b<p;b++){var d=n[b];j.call(a,d)&&c.push(d)}return c}}if(!Date.prototype.toISOString)Date.prototype.toISOString=function(){return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate()+"T"+this.getHours()+":"+this.getMinutes()+":"+this.getSeconds()+"Z"};if(!Date.now)Date.now=function(){return(new Date).getTime()};if(!Date.prototype.toJSON)Date.prototype.toJSON=function(){if(typeof this.toISOString!="function")throw new TypeError;return this.toISOString()};if(isNaN(Date.parse("T00:00")))Date=
function(a){var c=function(e,f,h,g,k,o,r){var i=arguments.length;if(this instanceof a){i=i===1&&String(e)===e?new a(c.parse(e)):i>=7?new a(e,f,h,g,k,o,r):i>=6?new a(e,f,h,g,k,o):i>=5?new a(e,f,h,g,k):i>=4?new a(e,f,h,g):i>=3?new a(e,f,h):i>=2?new a(e,f):i>=1?new a(e):new a;i.constructor=c;return i}return a.apply(this,arguments)},b=RegExp("^(?:((?:[+-]\\d\\d)?\\d\\d\\d\\d)(?:-(\\d\\d)(?:-(\\d\\d))?)?)?(?:T(\\d\\d):(\\d\\d)(?::(\\d\\d)(?:\\.(\\d\\d\\d))?)?)?(?:Z|([+-])(\\d\\d):(\\d\\d))?$"),d;for(d in a)c[d]=
a[d];c.now=a.now;c.UTC=a.UTC;c.prototype=a.prototype;c.prototype.constructor=c;c.parse=function(e){var f=b.exec(e);if(f){f.shift();for(var h=f[0]===undefined,g=0;g<10;g++)if(g!==7){f[g]=+(f[g]||(g<3?1:0));g===1&&f[g]--}if(h)return((f[3]*60+f[4])*60+f[5])*1E3+f[6];h=(f[8]*60+f[9])*60*1E3;if(f[6]==="-")h=-h;return a.UTC.apply(this,f.slice(0,7))+h}return a.parse.apply(this,arguments)};return c}(Date);var l=Array.prototype.slice;if(!Function.prototype.bind)Function.prototype.bind=function(a){var c=this;
if(typeof c.apply!="function"||typeof c.call!="function")return new TypeError;var b=l.call(arguments),d=function(){if(this instanceof d){var e=Object.create(c.prototype);c.apply(e,b.concat(l.call(arguments)));return e}else return c.call.apply(c,b.concat(l.call(arguments)))};d.bound=c;d.boundTo=a;d.boundArgs=b;d.length=typeof c=="function"?Math.max(c.length-b.length,0):0;return d};if(!String.prototype.trim){var s=/^\s\s*/,t=/\s\s*$/;String.prototype.trim=function(){return String(this).replace(s,"").replace(t,
"")}}})();

0
src/test/javascript/loadTest.js Executable file → Normal file
View File

0
src/test/javascript/loadTestTwo.js Executable file → Normal file
View File

0
src/test/javascript/sources/source1.js Executable file → Normal file
View File

0
src/test/javascript/sources/source2.js Executable file → Normal file
View File

0
src/test/javascript/specs/crashingJSCode.js Executable file → Normal file
View File

0
src/test/javascript/specs/crashingSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/emptySpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/envUtilsSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/failingSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/fixtures/formevents.html vendored Executable file → Normal file
View File

0
src/test/javascript/specs/fixtures/styleAttributes.html vendored Executable file → Normal file
View File

0
src/test/javascript/specs/recursiveSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/spec1.js Executable file → Normal file
View File

0
src/test/javascript/specs/spec2.js Executable file → Normal file
View File

View File

@ -0,0 +1,4 @@
// loadsJSFilesFromClasspathTarget.js
var target = {
theAnswer: "forty two"
};