Repository: zest-qi4j Updated Branches: refs/heads/develop e44fb652d -> 72e375eb6
http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/README.txt ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/README.txt b/libraries/lang-jruby/README.txt new file mode 100644 index 0000000..4cb1b55 --- /dev/null +++ b/libraries/lang-jruby/README.txt @@ -0,0 +1,10 @@ + +BeanShell is licensed under LGPL, and Apache Software Foundation +doesn't allow the use of LGPL in Apache projects. + +Therefor, Apache Zest had to drop this library component, but +it is still available for separate download at + +https://github.com/Qi4j/qi4j-sdk + +in the libraries/lang-beanshell directory. http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/build.gradle ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/build.gradle b/libraries/lang-jruby/build.gradle deleted file mode 100644 index 0d1ecbb..0000000 --- a/libraries/lang-jruby/build.gradle +++ /dev/null @@ -1,15 +0,0 @@ -description = "Qi4j JRuby Library allows for Mixins to be implemented in JRuby scripts instead of directly in compiled Java." - -jar { manifest { name = "Qi4j Library - Scripting - JRuby" }} - - -dependencies { - compile(project(":org.qi4j.core:org.qi4j.core.bootstrap")) - compile( project( ':org.qi4j.libraries:org.qi4j.library.scripting' )) - compile(libraries.jruby) - - testCompile(project(":org.qi4j.core:org.qi4j.core.testsupport")) - - testRuntime(project(":org.qi4j.core:org.qi4j.core.runtime")) - testRuntime(libraries.logback) -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/dev-status.xml ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/dev-status.xml b/libraries/lang-jruby/dev-status.xml deleted file mode 100644 index cefc98a..0000000 --- a/libraries/lang-jruby/dev-status.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.qi4j.org/schemas/2008/dev-status/1 - http://www.qi4j.org/schemas/2008/dev-status/1/dev-status.xsd"> - <status> - <!--none,early,beta,stable,mature--> - <codebase>beta</codebase> - - <!-- none, brief, good, complete --> - <documentation>brief</documentation> - - <!-- none, some, good, complete --> - <unittests>some</unittests> - </status> - <licenses> - <license>ALv2</license> - </licenses> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/licenses/jruby.license ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/licenses/jruby.license b/libraries/lang-jruby/licenses/jruby.license deleted file mode 100644 index 64b9511..0000000 --- a/libraries/lang-jruby/licenses/jruby.license +++ /dev/null @@ -1,60 +0,0 @@ -JRuby distributes some ruby modules which are distributed under Ruby -license: - -Ruby is copyrighted free software by Yukihiro Matsumoto <[email protected]>. -You can redistribute it and/or modify it under either the terms of the GPL -(see the file GPL), or the conditions below: - - 1. You may make and give away verbatim copies of the source form of the - software without restriction, provided that you duplicate all of the - original copyright notices and associated disclaimers. - - 2. You may modify your copy of the software in any way, provided that - you do at least ONE of the following: - - a) place your modifications in the Public Domain or otherwise - make them Freely Available, such as by posting said -modifications to Usenet or an equivalent medium, or by allowing -the author to include your modifications in the software. - - b) use the modified software only within your corporation or - organization. - - c) give non-standard binaries non-standard names, with - instructions on where to get the original software distribution. - - d) make other distribution arrangements with the author. - - 3. You may distribute the software in object code or binary form, - provided that you do at least ONE of the following: - - a) distribute the binaries and library files of the software, -together with instructions (in the manual page or equivalent) -on where to get the original distribution. - - b) accompany the distribution with the machine-readable source of -the software. - - c) give non-standard binaries non-standard names, with - instructions on where to get the original software distribution. - - d) make other distribution arrangements with the author. - - 4. You may modify and include the part of the software into any other - software (possibly commercial). But some files in the distribution - are not written by the author, so that they are not under these terms. - - For the list of those files and their copying conditions, see the - file LEGAL. - - 5. The scripts and library files supplied as input to or produced as - output from the software do not automatically fall under the - copyright of the software, but belong to whomever generated them, - and may be sold commercially, and may be aggregated with this - software. - - 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. - http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/docs/lang-jruby.txt ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/docs/lang-jruby.txt b/libraries/lang-jruby/src/docs/lang-jruby.txt deleted file mode 100644 index a7113c2..0000000 --- a/libraries/lang-jruby/src/docs/lang-jruby.txt +++ /dev/null @@ -1,29 +0,0 @@ -[[library-script-jruby, JRuby Scripting Library]] -= JRuby Scripting = - -[devstatus] --------------- -source=libraries/lang-jruby/dev-status.xml --------------- - -The JRuby Scripting Library allows Mixin methods to be implemented in Ruby and loaded dynamically on first use. - -include::../../build/docs/buildinfo/artifact.txt[] - -The JRuby Scripting Library is a Generic mixin that implements interfaces by delegating to Ruby functions using JRuby. Each method in an interface is declared by a Ruby method in a file located in classpath with the name "<interface>.rb", where the interface name includes the package, and has "." replaced with "/". - -Example: - - org/qi4j/samples/hello/domain/HelloWorldSpeaker.rb - -That means that the HelloWorldSpeaker.rb file may be co-located with the class files in the same package. It is currently not supported to place the JRuby implementation of the mixin in a different package than the interface it implements. - -To use JRuby to implement the Mixin functionality for a given interface, -simply declare the +JRubyMixin+ like any other mixin, either in the interface -or at assembly time. - -[snippet,java] ----- -source=libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/HelloSpeaker.java -tag=mixin ----- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/JRubyMixin.java ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/JRubyMixin.java b/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/JRubyMixin.java deleted file mode 100644 index 9d4bd01..0000000 --- a/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/JRubyMixin.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2007 Rickard Ãberg - * 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 org.qi4j.lang.jruby; - -import java.io.*; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import org.jruby.*; -import org.jruby.exceptions.RaiseException; -import org.jruby.internal.runtime.methods.CallConfiguration; -import org.jruby.internal.runtime.methods.DynamicMethod; -import org.jruby.javasupport.JavaEmbedUtils; -import org.jruby.runtime.Block; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.Visibility; -import org.jruby.runtime.builtin.IRubyObject; -import org.qi4j.api.common.AppliesTo; -import org.qi4j.api.common.AppliesToFilter; -import org.qi4j.api.composite.Composite; -import org.qi4j.api.composite.TransientBuilderFactory; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.property.Property; -import org.qi4j.library.scripting.ScriptReloadable; - -/** - * Generic mixin that implements interfaces by delegating to Ruby functions - * using JRuby. Each method in an interface is declared by a Ruby method - * in a file located in classpath with the name "<interface>.rb", - * where the interface name includes the package, and has "." replaced with "/". - * <p> - * Example: - * </p> - * <pre><code> - * org/qi4j/samples/hello/domain/HelloWorldSpeaker.rb - * </code></pre> - */ -@AppliesTo( JRubyMixin.AppliesTo.class ) -public class JRubyMixin - implements InvocationHandler, ScriptReloadable -{ - @This private Composite me; - - @Service private Ruby runtime; - - private Map<Class, IRubyObject> rubyObjects = new HashMap<Class, IRubyObject>(); - - public static class AppliesTo - implements AppliesToFilter - { - - @Override - public boolean appliesTo( Method method, Class compositeType, Class mixin, Class modelClass ) - { - return getFunctionResoure( method ) != null; - } - - } - - @Structure TransientBuilderFactory factory; - - @Override - public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable - { - try - { - // Get Ruby object for declaring class of the method - Class declaringClass = method.getDeclaringClass(); - IRubyObject rubyObject = rubyObjects.get( declaringClass ); - - // If not yet created, create one - if( rubyObject == null ) - { - // Create object instance - try - { - rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); - } - catch( RaiseException e ) - { - if( e.getException() instanceof RubyNameError ) - { - // Initialize Ruby class - String script = getFunction( method ); - runtime.evalScriptlet( script ); - - // Try creating a Ruby instance again - rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); - } - else - { - throw e; - } - } - - // Set @this variable to Composite - IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); - RubyClass rubyClass = meRuby.getMetaClass(); - if( !rubyClass.isFrozen() ) - { - SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); - GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); - Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); - for( Method compositeMethod : compositeMethods ) - { - if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) - { - - rubyClass.addMethod( compositeMethod.getName() + "=", setter ); - rubyClass.addMethod( compositeMethod.getName(), getter ); - } - } - rubyClass.freeze( ThreadContext.newContext( runtime ) ); - } - - RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); - rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); - rubyObjects.put( declaringClass, rubyObject ); - } - - // Convert method arguments and invoke the method - IRubyObject rubyResult; - if( args != null ) - { - IRubyObject[] rubyArgs = new IRubyObject[args.length]; - for( int i = 0; i < args.length; i++ ) - { - Object arg = args[ i ]; - rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); - } - rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); - } - else - { - rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); - } - - // Convert result to Java - Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); - return result; - } - catch( Exception e ) - { - e.printStackTrace(); - throw e; - } - } - - @Override - public void reloadScripts() - { - rubyObjects.clear(); - } - - protected String getFunction( Method aMethod ) - throws IOException - { - URL scriptUrl = getFunctionResoure( aMethod ); - - if( scriptUrl == null ) - { - throw new IOException( "No script found for method " + aMethod.getName() ); - } - - InputStream in = scriptUrl.openStream(); - BufferedReader scriptReader = new BufferedReader( new InputStreamReader( in ) ); - String line; - StringBuilder sb = new StringBuilder(); - while( ( line = scriptReader.readLine() ) != null ) - { - sb.append( line ).append( "\n" ); - } - return sb.toString(); - } - - protected static URL getFunctionResoure( Method method ) - { - Class<?> declaringClass = method.getDeclaringClass(); - String classname = declaringClass.getName(); - String scriptFile = classname.replace( '.', File.separatorChar ) + ".rb"; - ClassLoader loader = declaringClass.getClassLoader(); - URL scriptUrl = loader.getResource( scriptFile ); - return scriptUrl; - } - - private static class SetterDynamicMethod - extends DynamicMethod - { - private SetterDynamicMethod( RubyModule rubyModule, Visibility visibility, CallConfiguration callConfiguration ) - { - super( rubyModule, visibility, callConfiguration ); - } - - @Override - public IRubyObject call( ThreadContext threadContext, IRubyObject iRubyObject, RubyModule rubyModule, String methodName, IRubyObject[] iRubyObjects, Block block ) - { - String propertyName = methodName.substring( 0, methodName.length() - 1 ); - IRubyObject prop = iRubyObject.callMethod( threadContext, propertyName ); - prop.callMethod( threadContext, "set", iRubyObjects ); - return null; - } - - @Override - public DynamicMethod dup() - { - return this; - } - - } - - private static class GetterDynamicMethod - extends DynamicMethod - { - private GetterDynamicMethod( RubyModule rubyModule, Visibility visibility, CallConfiguration callConfiguration ) - { - super( rubyModule, visibility, callConfiguration ); - } - - @Override - public IRubyObject call( ThreadContext threadContext, IRubyObject iRubyObject, RubyModule rubyModule, String methodName, IRubyObject[] iRubyObjects, Block block ) - { - try - { - String propertyName = methodName; - Object thisComposite = JavaEmbedUtils.rubyToJava( iRubyObject.getRuntime(), iRubyObject, Object.class ); - Method propertyMethod = thisComposite.getClass().getMethod( propertyName ); - Property property = (Property) propertyMethod.invoke( thisComposite ); - Object propertyValue = property.get(); - IRubyObject prop = JavaEmbedUtils.javaToRuby( iRubyObject.getRuntime(), propertyValue ); - return prop; - } - catch( Exception e ) - { - throw new RaiseException( new RubyNameError( iRubyObject.getRuntime(), iRubyObject.getMetaClass(), "Could not find property " + methodName ) ); - } - } - - @Override - public DynamicMethod dup() - { - return this; - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/package.html ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/package.html b/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/package.html deleted file mode 100644 index b42f7e3..0000000 --- a/libraries/lang-jruby/src/main/java/org/qi4j/lang/jruby/package.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - <h2>Ruby Language Support Library.</h2> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/HelloSpeaker.java ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/HelloSpeaker.java b/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/HelloSpeaker.java deleted file mode 100644 index 1aa9641..0000000 --- a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/HelloSpeaker.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2007 Rickard Ãberg - * 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 org.qi4j.lang.jruby; - -import org.qi4j.api.mixin.Mixins; - -// START SNIPPET: mixin -import org.qi4j.lang.jruby.JRubyMixin; - -@Mixins(JRubyMixin.class) -public interface HelloSpeaker -{ - void sayHello(); -} -// END SNIPPET: mixin http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/JRubyMixinTest.java ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/JRubyMixinTest.java b/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/JRubyMixinTest.java deleted file mode 100644 index 433d62f..0000000 --- a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/JRubyMixinTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.qi4j.lang.jruby; -/* - * Copyright 2007 Rickard Ãberg - * 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. -*/ - -import org.jruby.Ruby; -import org.junit.Assert; -import org.junit.Test; -import org.qi4j.api.service.importer.InstanceImporter; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.AbstractQi4jTest; - -public class JRubyMixinTest extends AbstractQi4jTest -{ - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.transients( MyDomainType.class ).withMixins( JRubyMixin.class ); - - Ruby ruby = Ruby.newInstance(); - module.importedServices( Ruby.class ).importedBy( InstanceImporter.class ).setMetaInfo( ruby ); - } - - @Test - public void testInvoke() - throws Throwable - { - MyDomainType domain = module.newTransientBuilder( MyDomainType.class ).newInstance(); - - Assert.assertEquals( "do1() in Ruby mixin.", domain.do1() ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/MyDomainType.java ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/MyDomainType.java b/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/MyDomainType.java deleted file mode 100644 index 4e4d36c..0000000 --- a/libraries/lang-jruby/src/test/java/org/qi4j/lang/jruby/MyDomainType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.qi4j.lang.jruby; - -public interface MyDomainType -{ - String do1(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/libraries/lang-jruby/src/test/resources/org/qi4j/lang/jruby/MyDomainType.rb ---------------------------------------------------------------------- diff --git a/libraries/lang-jruby/src/test/resources/org/qi4j/lang/jruby/MyDomainType.rb b/libraries/lang-jruby/src/test/resources/org/qi4j/lang/jruby/MyDomainType.rb deleted file mode 100644 index a3a8a52..0000000 --- a/libraries/lang-jruby/src/test/resources/org/qi4j/lang/jruby/MyDomainType.rb +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2007 Rickard Oberg -# 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. -# - -class MyDomainType - def do1 - return "do1() in Ruby mixin." - end -end http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/060bb358/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index f7a72ac..5dae8fb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,10 +16,8 @@ include "core:functional", 'libraries:fileconfig', 'libraries:http', 'libraries:invocation-cache', - 'libraries:lang-beanshell', 'libraries:lang-groovy', 'libraries:lang-javascript', - 'libraries:lang-jruby', 'libraries:lang-scala', 'libraries:jmx', 'libraries:locking',
