Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Code generator that adapts the core Observable to a dynamic langu…
…age's native function support

* Only hooked up to rxjava-groovy in this commit
  • Loading branch information
mattrjacobs committed Jul 4, 2013
commit c93ba88e8bdc797376b0fb9f6ebddf531a9755cb
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ apply from: file('gradle/maven.gradle')
apply from: file('gradle/license.gradle')
apply from: file('gradle/release.gradle')

ext.coreJarDir = new File(rootDir, "/rxjava-core/build/libs").getCanonicalPath()

subprojects {

group = "com.netflix.${githubProjectName}"
Expand Down
50 changes: 50 additions & 0 deletions language-adaptors/codegen/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'osgi'

dependencies {
compile project(':rxjava-core')
compile 'org.javassist:javassist:3.17.1-GA'

provided 'junit:junit:4.10'
provided 'org.mockito:mockito-core:1.8.5'
}

//task createDynamicallyAdaptedObservable(type: JavaExec) {
// main = 'rx.lang.utils.LanguageAdaptorCodeGenerator'
// classpath = sourceSets.main.runtimeClasspath
// args dynamicClassDir

// FileTree coreTree = fileTree('../../rxjava-core/src/main').include('**/*.java')
// FileTree adaptorTree = fileTree('src/main').include("**/*.java")
// inputs.files (coreTree + adaptorTree)
//}

eclipse {
classpath {
// include 'provided' dependencies on the classpath
plusConfigurations += configurations.provided

downloadSources = true
downloadJavadoc = true
}
}

idea {
module {
// include 'provided' dependencies on the classpath
scopes.PROVIDED.plus += configurations.provided
}
}

jar {
manifest {
name = 'rxjava-language-adaptor-utils'
instruction 'Bundle-Vendor', 'Netflix'
instruction 'Bundle-DocURL', 'https://github.com/Netflix/RxJava'
instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*'
instruction 'Fragment-Host', 'com.netflix.rxjava.core'
}
}
47 changes: 47 additions & 0 deletions language-adaptors/codegen/examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Here's the example source of Observable (heavily elided):

public class rx.Observable {
public static <T> Observable<T> create(Func1<Observer<T>, Subscription> func) {
return new Observable<T>(func);
}

public static <T> Observable<T> create(Object func) {
...
}

public static <T> Observable<T> take(final Observable<T> items, final int num) {
return create(OperationTake.take(items, num));
}

public static <T> Observable<T> takeWhile(final Observable<T> items, Func1<T, Boolean> predicate) {
return create(OperationTakeWhile.takeWhile(items, predicate));
}

public Observable<T> filter(Func1<T, Boolean> predicate) {
return filter(this, predicate);
}

public static <T> Observable<T> filter(Observable<T> that, Func1<T, Boolean> predicate) {
return create(OperationFilter.filter(that, predicate));
}
}

Groovy-friendly version adds:

public class rx.Observable {
public static <T> rx.Observable<T> create(groovy.lang.Closure func) {
return create(new GroovyFunctionAdaptor(func));
}

public static <T> rx.Observable<T> takeWhile(final Observable<T> items, groovy.lang.Closure predicate) {
return takeWhile(items, new GroovyFunctionAdaptor(predicate));
}

public rx.Observable<T> filter(groovy.lang.Closure predicate) {
return filter(new GroovyFunctionAdaptor(predicate));
}

public static <T> rxObservable<T> filter(Observable<T> that, groovy.lang.Closure predicate) {
return filter(that, new GroovyFunctionAdaptor(predicate));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package rx.codegen;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import rx.util.functions.FunctionLanguageAdaptor;

public class ClassPathBasedRunner {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage : Expects 2 args: (Language, File to place classfiles)");
System.out.println("Currently supported languages: Groovy/Clojure/JRuby");
System.exit(1);
}
String lang = args[0];
File dir = new File(args[1]);
System.out.println("Looking for Adaptor for : " + lang);
String className = "rx.lang." + lang.toLowerCase() + "." + lang + "Adaptor";
try {
Class<?> adaptorClass = Class.forName(className);
System.out.println("Found Adaptor : " + adaptorClass);
FunctionLanguageAdaptor adaptor = (FunctionLanguageAdaptor) adaptorClass.newInstance();

CodeGenerator codeGen = new CodeGenerator();
System.out.println("Using dir : " + dir + " for outputting classfiles");
for (Class<?> observableClass: getObservableClasses()) {
codeGen.addMethods(observableClass, adaptor, new File(args[1]));
}
} catch (ClassNotFoundException ex) {
System.out.println("Did not find adaptor class : " + className);
System.exit(1);
} catch (InstantiationException ex) {
System.out.println("Reflective constuctor on : " + className + " failed");
System.exit(1);
} catch (IllegalAccessException ex) {
System.out.println("Access to constructor on : " + className + " failed");
System.exit(1);
}
}

private static List<Class<?>> getObservableClasses() {
List<Class<?>> observableClasses = new ArrayList<Class<?>>();
observableClasses.add(rx.Observable.class);
observableClasses.add(rx.observables.BlockingObservable.class);
return observableClasses;
}
}
Loading