Search in sources :

Example 1 with JavaForMvelDialectConfiguration

use of org.drools.mvel.java.JavaForMvelDialectConfiguration in project drools by kiegroup.

the class KnowledgeBuilderTest method testCompilerConfiguration.

@Test
public void testCompilerConfiguration() throws Exception {
    // test default is eclipse jdt core
    KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
    PackageDescr pkgDescr = new PackageDescr("org.drools.mvel.compiler.test");
    builder.addPackage(pkgDescr);
    DialectCompiletimeRegistry reg = builder.getPackageRegistry(pkgDescr.getName()).getDialectCompiletimeRegistry();
    final Field dialectField = builder.getClass().getDeclaredField("defaultDialect");
    dialectField.setAccessible(true);
    String dialectName = (String) dialectField.get(builder);
    reg = builder.getPackageRegistry(pkgDescr.getName()).getDialectCompiletimeRegistry();
    Dialect dialect = reg.getDialect(dialectName);
    final Field compilerField = dialect.getClass().getDeclaredField("compiler");
    compilerField.setAccessible(true);
    JavaCompiler compiler = (JavaCompiler) compilerField.get(dialect);
    KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
    JavaForMvelDialectConfiguration javaConf = (JavaForMvelDialectConfiguration) conf.getDialectConfiguration("java");
    switch(javaConf.getCompiler()) {
        case NATIVE:
            assertSame(NativeJavaCompiler.class, compiler.getClass());
            break;
        case ECLIPSE:
            assertSame(EclipseJavaCompiler.class, compiler.getClass());
            break;
        default:
            fail("Unrecognized java compiler");
    }
    // test eclipse jdt core with property settings and default source level
    conf = new KnowledgeBuilderConfigurationImpl();
    javaConf = (JavaForMvelDialectConfiguration) conf.getDialectConfiguration("java");
    javaConf.setCompiler(JavaForMvelDialectConfiguration.CompilerType.ECLIPSE);
    builder = new KnowledgeBuilderImpl(conf);
    builder.addPackage(pkgDescr);
    dialectName = (String) dialectField.get(builder);
    reg = builder.getPackageRegistry(pkgDescr.getName()).getDialectCompiletimeRegistry();
    dialect = reg.getDialect(dialectName);
    compiler = (JavaCompiler) compilerField.get(dialect);
    assertSame(EclipseJavaCompiler.class, compiler.getClass());
}
Also used : FactField(org.kie.api.definition.type.FactField) Field(java.lang.reflect.Field) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Dialect(org.drools.compiler.compiler.Dialect) NativeJavaCompiler(org.kie.memorycompiler.jdknative.NativeJavaCompiler) JavaCompiler(org.kie.memorycompiler.JavaCompiler) EclipseJavaCompiler(org.drools.ecj.EclipseJavaCompiler) JavaForMvelDialectConfiguration(org.drools.mvel.java.JavaForMvelDialectConfiguration) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 2 with JavaForMvelDialectConfiguration

use of org.drools.mvel.java.JavaForMvelDialectConfiguration in project drools by kiegroup.

the class JavaForMvelDialectConfigurationTest method checkVersion.

@Test
public void checkVersion() {
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("1.5");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("1.6");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("1.7");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("9");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("10");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("11");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("12");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("13");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("14");
    new JavaForMvelDialectConfiguration().setJavaLanguageLevel("15");
}
Also used : JavaForMvelDialectConfiguration(org.drools.mvel.java.JavaForMvelDialectConfiguration) Test(org.junit.Test)

Example 3 with JavaForMvelDialectConfiguration

use of org.drools.mvel.java.JavaForMvelDialectConfiguration in project drools by kiegroup.

the class PackageBuilderConfigurationTest method testProgramaticProperties2.

@Test
public void testProgramaticProperties2() {
    JavaForMvelDialectConfiguration javaConf = new JavaForMvelDialectConfiguration();
    javaConf.init(new KnowledgeBuilderConfigurationImpl());
    javaConf.setCompiler(JavaForMvelDialectConfiguration.CompilerType.ECLIPSE);
    KnowledgeBuilderConfigurationImpl cfg = new KnowledgeBuilderConfigurationImpl();
    cfg.setDialectConfiguration("java", javaConf);
    JavaForMvelDialectConfiguration javaConf2 = (JavaForMvelDialectConfiguration) cfg.getDialectConfiguration("java");
    assertSame(javaConf, javaConf2);
    assertEquals(JavaForMvelDialectConfiguration.CompilerType.ECLIPSE, javaConf2.getCompiler());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) JavaForMvelDialectConfiguration(org.drools.mvel.java.JavaForMvelDialectConfiguration) Test(org.junit.Test)

Aggregations

JavaForMvelDialectConfiguration (org.drools.mvel.java.JavaForMvelDialectConfiguration)3 Test (org.junit.Test)3 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 Field (java.lang.reflect.Field)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 Dialect (org.drools.compiler.compiler.Dialect)1 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 EclipseJavaCompiler (org.drools.ecj.EclipseJavaCompiler)1 FactField (org.kie.api.definition.type.FactField)1 JavaCompiler (org.kie.memorycompiler.JavaCompiler)1 NativeJavaCompiler (org.kie.memorycompiler.jdknative.NativeJavaCompiler)1