Search in sources :

Example 1 with CompiledProcessorSupport

use of org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport in project legend-pure by finos.

the class Test_PureTestSuite method getClassLoaderExecutionSupport.

public static CompiledExecutionSupport getClassLoaderExecutionSupport() {
    MutableList<CodeRepository> codeRepos = Lists.mutable.of(CodeRepository.newPlatformCodeRepository()).withAll(CodeRepositoryProviderHelper.findCodeRepositories());
    ClassLoader classLoader = Test_PureTestSuite.class.getClassLoader();
    return new CompiledExecutionSupport(new JavaCompilerState(null, classLoader), new CompiledProcessorSupport(classLoader, MetadataLazy.fromClassLoader(classLoader), Sets.mutable.empty()), null, new PureCodeStorage(null, new ClassLoaderCodeStorage(classLoader, codeRepos)), null, null, new ConsoleCompiled(), new FunctionCache(), new ClassCache(classLoader), null, Sets.mutable.empty());
}
Also used : CompiledProcessorSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport) CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository) JavaCompilerState(org.finos.legend.pure.runtime.java.compiled.compiler.JavaCompilerState) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) ClassCache(org.finos.legend.pure.runtime.java.compiled.metadata.ClassCache) ConsoleCompiled(org.finos.legend.pure.runtime.java.compiled.execution.ConsoleCompiled) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) FunctionCache(org.finos.legend.pure.runtime.java.compiled.metadata.FunctionCache)

Example 2 with CompiledProcessorSupport

use of org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport in project legend-pure by finos.

the class CompiledSupport method dynamicallyEvaluateValueSpecification.

public static Object dynamicallyEvaluateValueSpecification(final CoreInstance valueSpecification, PureMap lambdaOpenVariablesMap, ExecutionSupport es) {
    MemoryFileManager fileManager = ((CompiledExecutionSupport) es).getMemoryFileManager();
    ClassLoader globalClassLoader = ((CompiledExecutionSupport) es).getClassLoader();
    final CompiledProcessorSupport compiledSupport = new CompiledProcessorSupport(globalClassLoader, ((CompiledExecutionSupport) es).getMetadata(), ((CompiledExecutionSupport) es).getExtraSupportedTypes());
    final ProcessorContext processorContext = new ProcessorContext(compiledSupport);
    // Don't do anything if the ValueSpecification is already resolved ----------------
    if (Instance.instanceOf(valueSpecification, M3Paths.InstanceValue, processorContext.getSupport())) {
        ListIterable<? extends CoreInstance> l = valueSpecification.getValueForMetaPropertyToMany(M3Properties.values);
        if (l.noneSatisfy(instance -> Instance.instanceOf(instance, M3Paths.ValueSpecification, processorContext.getSupport()) || Instance.instanceOf(instance, M3Paths.LambdaFunction, processorContext.getSupport()))) {
            ListIterable<Object> result = l.collect(instance -> instance instanceof ValCoreInstance ? ((ValCoreInstance) instance).getValue() : instance);
            return result.size() == 1 ? result.get(0) : result;
        }
    }
    // ---------------------------------------------------------------------------------
    processorContext.setInLineAllLambda(true);
    String processed = ValueSpecificationProcessor.processValueSpecification(valueSpecification, true, processorContext);
    String returnType = TypeProcessor.typeToJavaObjectWithMul(valueSpecification.getValueForMetaPropertyToOne(M3Properties.genericType), valueSpecification.getValueForMetaPropertyToOne(M3Properties.multiplicity), false, compiledSupport);
    String name = "DynaClass";
    RichIterable<Pair<String, CoreInstance>> values = lambdaOpenVariablesMap.getMap().keyValuesView();
    final MutableMap<String, Object> openVars = Maps.mutable.of();
    String _class = JavaSourceCodeGenerator.imports + "\npublic class " + name + "{\n" + "   public static " + returnType + " doProcess(final MapIterable<String, Object> vars, final MutableMap<String, Object> valMap, final IntObjectMap<CoreInstance> localLambdas, final ExecutionSupport es){\n" + values.collect(new Function<Pair<String, CoreInstance>, String>() {

        @Override
        public String valueOf(Pair<String, CoreInstance> pair) {
            final String name = pair.getOne();
            CoreInstance valuesCoreInstance = pair.getTwo();
            ListIterable<? extends CoreInstance> values = valuesCoreInstance.getValueForMetaPropertyToMany(M3Properties.values).select(coreInstance -> !Instance.instanceOf(coreInstance, "meta::pure::executionPlan::PlanVarPlaceHolder", compiledSupport) && !Instance.instanceOf(coreInstance, "meta::pure::executionPlan::PlanVariablePlaceHolder", compiledSupport));
            String type = null;
            openVars.put(name, valuesCoreInstance);
            if (values.isEmpty()) {
                MutableList<CoreInstance> vars = FastList.newList();
                collectVars(valueSpecification, vars, compiledSupport);
                CoreInstance found = vars.detect(coreInstance -> coreInstance.getValueForMetaPropertyToOne("name").getName().equals(name));
                if (found != null) {
                    type = TypeProcessor.typeToJavaObjectSingle(found.getValueForMetaPropertyToOne(M3Properties.genericType), false, compiledSupport);
                    return "      final  " + type + "  _" + name + " = null;";
                }
                return "";
            } else {
                type = TypeProcessor.pureRawTypeToJava(compiledSupport.getClassifier(values.getFirst()), false, compiledSupport);
                final String listImpl = JavaPackageAndImportBuilder.buildImplClassReferenceFromUserPath(M3Paths.List);
                return (values.size() == 1) ? ("      final " + type + " _" + name + " = (" + type + ")((" + listImpl + ")vars.get(\"" + name + "\"))._values.getFirst();") : ("      final RichIterable<" + type + "> _" + name + " = ((" + listImpl + ")vars.get(\"" + name + "\"))._values;");
            }
        }
    }).makeString("\n") + "       return " + processed + ";\n" + "   }\n" + "}\n";
    String javaPackage = JavaPackageAndImportBuilder.buildPackageForPackageableElement(valueSpecification);
    ListIterable<StringJavaSource> javaClasses = Lists.immutable.with(StringJavaSource.newStringJavaSource(javaPackage, name, _class));
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    MemoryFileManager manager = new MemoryFileManager(compiler, fileManager, null);
    try {
        PureJavaCompiler.compile(compiler, javaClasses, manager);
    } catch (Exception e) {
        StringBuilder message = new StringBuilder("Error dynamically evaluating value specification");
        SourceInformation valueSpecSourceInfo = valueSpecification.getSourceInformation();
        if (valueSpecSourceInfo != null) {
            valueSpecSourceInfo.appendMessage(message.append(" (from ")).append(')');
        }
        message.append("; error compiling generated Java code:\n").append(_class);
        throw new RuntimeException(message.toString(), e);
    }
    ClassLoader cl = new MemoryClassLoader(manager, globalClassLoader);
    try {
        Class<?> realClass = cl.loadClass(javaPackage + "." + name);
        return realClass.getMethod("doProcess", MapIterable.class, MutableMap.class, IntObjectMap.class, ExecutionSupport.class).invoke(null, openVars, processorContext.getObjectToPassToDynamicallyGeneratedCode(), processorContext.getLocalLambdas(), es);
    } catch (Exception e) {
        StringBuilder message = new StringBuilder("Error dynamically evaluating value specification");
        SourceInformation valueSpecSourceInfo = valueSpecification.getSourceInformation();
        if (valueSpecSourceInfo != null) {
            valueSpecSourceInfo.appendMessage(message.append(" (from ")).append(')');
        }
        String errorMessage = e.getMessage();
        if (errorMessage != null) {
            message.append(": ").append(errorMessage);
        }
        throw new RuntimeException(message.toString(), e);
    }
}
Also used : MutableMap(org.eclipse.collections.api.map.MutableMap) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext) CompiledProcessorSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport) SharedPureFunction(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.SharedPureFunction) Function(org.eclipse.collections.api.block.function.Function) JavaMethodWithParamsSharedPureFunction(org.finos.legend.pure.runtime.java.compiled.metadata.JavaMethodWithParamsSharedPureFunction) IntObjectMap(org.eclipse.collections.api.map.primitive.IntObjectMap) MemoryClassLoader(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryClassLoader) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) ExecutionSupport(org.finos.legend.pure.m3.execution.ExecutionSupport) StringJavaSource(org.finos.legend.pure.runtime.java.compiled.compiler.StringJavaSource) MemoryClassLoader(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryClassLoader) MemoryFileManager(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryFileManager) Pair(org.eclipse.collections.api.tuple.Pair) ValCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ValCoreInstance) JavaCompiler(javax.tools.JavaCompiler) PureJavaCompiler(org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompiler) MapIterable(org.eclipse.collections.api.map.MapIterable) PureAssertFailException(org.finos.legend.pure.m3.exception.PureAssertFailException) InvalidFunctionDescriptorException(org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PureJavaCompileException(org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompileException) PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) ParseException(org.json.simple.parser.ParseException) NoSuchElementException(java.util.NoSuchElementException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ValCoreInstance) BaseCoreInstance(org.finos.legend.pure.m3.coreinstance.BaseCoreInstance) ReflectiveCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ReflectiveCoreInstance) AbstractCoreInstance(org.finos.legend.pure.m4.coreinstance.AbstractCoreInstance) JavaCompiledCoreInstance(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.JavaCompiledCoreInstance)

Example 3 with CompiledProcessorSupport

use of org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport in project legend-pure by finos.

the class CompiledSupport method dynamicallyBuildLambdaFunction.

public static Object dynamicallyBuildLambdaFunction(CoreInstance lambdaFunction, ExecutionSupport es) {
    ClassLoader globalClassLoader = ((CompiledExecutionSupport) es).getClassLoader();
    CompiledProcessorSupport compiledSupport = new CompiledProcessorSupport(globalClassLoader, ((CompiledExecutionSupport) es).getMetadata(), ((CompiledExecutionSupport) es).getExtraSupportedTypes());
    ProcessorContext processorContext = new ProcessorContext(compiledSupport);
    processorContext.setInLineAllLambda(true);
    String name = "DynamicLambdaGeneration";
    String _class = JavaSourceCodeGenerator.imports + "\nimport " + JavaPackageAndImportBuilder.rootPackage() + ".*;\npublic class " + name + "{" + "   public static PureCompiledLambda build(final MutableMap<String, Object> valMap, final IntObjectMap<CoreInstance> localLambdas){\n" + "return " + ValueSpecificationProcessor.processLambda(null, lambdaFunction, compiledSupport, processorContext) + ";" + "}" + "}";
    MemoryFileManager fileManager = ((CompiledExecutionSupport) es).getMemoryFileManager();
    MutableList<StringJavaSource> javaClasses = FastList.newList();
    javaClasses.add(StringJavaSource.newStringJavaSource("temp", name, _class));
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    MemoryFileManager manager = new MemoryFileManager(compiler, fileManager, null);
    try {
        PureJavaCompiler.compile(compiler, javaClasses, manager);
    } catch (PureJavaCompileException e) {
        throw new RuntimeException(e);
    }
    ClassLoader cl = new MemoryClassLoader(manager, globalClassLoader);
    try {
        Class<?> realClass = cl.loadClass("temp" + "." + name);
        return realClass.getMethod("build", MutableMap.class, IntObjectMap.class).invoke(null, processorContext.getObjectToPassToDynamicallyGeneratedCode(), processorContext.getLocalLambdas());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MutableMap(org.eclipse.collections.api.map.MutableMap) JavaCompiler(javax.tools.JavaCompiler) PureJavaCompiler(org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompiler) PureAssertFailException(org.finos.legend.pure.m3.exception.PureAssertFailException) InvalidFunctionDescriptorException(org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PureJavaCompileException(org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompileException) PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) ParseException(org.json.simple.parser.ParseException) NoSuchElementException(java.util.NoSuchElementException) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext) CompiledProcessorSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport) IntObjectMap(org.eclipse.collections.api.map.primitive.IntObjectMap) PureJavaCompileException(org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompileException) MemoryClassLoader(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryClassLoader) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) StringJavaSource(org.finos.legend.pure.runtime.java.compiled.compiler.StringJavaSource) MemoryClassLoader(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryClassLoader) MemoryFileManager(org.finos.legend.pure.runtime.java.compiled.compiler.MemoryFileManager)

Example 4 with CompiledProcessorSupport

use of org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport in project legend-pure by finos.

the class Reactivator method reactivateWithoutJavaCompilationImpl.

private static Object reactivateWithoutJavaCompilationImpl(final ValueSpecification valueSpecification, final PureMap lambdaOpenVariablesMap, final ExecutionSupport es, final boolean atRoot, Bridge bridge) {
    if (valueSpecification instanceof RoutedValueSpecification) {
        return reactivateWithoutJavaCompilationImpl(((RoutedValueSpecification) valueSpecification)._value(), lambdaOpenVariablesMap, es, atRoot, bridge);
    } else if (valueSpecification instanceof InstanceValue) {
        InstanceValue iv = (InstanceValue) valueSpecification;
        RichIterable<?> result = iv._values().flatCollect(new org.eclipse.collections.api.block.function.Function<Object, RichIterable<Object>>() {

            @Override
            public RichIterable<Object> valueOf(Object value) {
                Object result;
                if (value instanceof ValueSpecification) {
                    result = reactivateWithoutJavaCompilationImpl((ValueSpecification) value, lambdaOpenVariablesMap, es, false, bridge);
                } else if ((!lambdaOpenVariablesMap.getMap().isEmpty()) && value instanceof KeyExpression) {
                    KeyExpression ke = (KeyExpression) value;
                    CompiledProcessorSupport processorSupport = ((CompiledExecutionSupport) es).getProcessorSupport();
                    Object key = reactivateWithoutJavaCompilationImpl(ke._key(), lambdaOpenVariablesMap, es, false, bridge);
                    InstanceValue rKey = (InstanceValue) ((CompiledExecutionSupport) es).getProcessorSupport().newCoreInstance("key", M3Paths.InstanceValue, null);
                    rKey._values(key instanceof RichIterable ? (RichIterable) key : Lists.immutable.with(key));
                    Object expression = reactivateWithoutJavaCompilationImpl(ke._expression(), lambdaOpenVariablesMap, es, false, bridge);
                    InstanceValue rExpression = (InstanceValue) ((CompiledExecutionSupport) es).getProcessorSupport().newCoreInstance("key", M3Paths.InstanceValue, null);
                    rExpression._values(expression instanceof RichIterable ? (RichIterable) expression : Lists.immutable.with(expression));
                    KeyExpression rKe = ke.copy();
                    rKe._key(rKey);
                    rKe._expression(rExpression);
                    result = rKe;
                } else if (value instanceof LambdaFunction) {
                    LambdaFunction lambdaFunction = (LambdaFunction) value;
                    UnifiedMap openVariables = UnifiedMap.newMap();
                    for (Object entry : lambdaOpenVariablesMap.getMap().keyValuesView()) {
                        Pair<String, org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List> pair = (Pair<String, org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List>) entry;
                        openVariables.put(pair.getOne(), pair.getTwo()._values());
                    }
                    for (Object entry : Pure.getOpenVariables(lambdaFunction, bridge).getMap().keyValuesView()) {
                        Pair<String, org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List> pair = (Pair<String, org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List>) entry;
                        openVariables.put(pair.getOne(), pair.getTwo()._values());
                    }
                    result = bridge.lambdaBuilder().value().lambdaFunction(lambdaFunction).pureFunction(DynamicPureLambdaFunctionImpl.createPureLambdaFunction(lambdaFunction, openVariables, bridge));
                } else {
                    result = value;
                }
                return CompiledSupport.toPureCollection(result);
            }
        });
        return (result != null) && (result.size() == 1) ? result.getFirst() : result;
    } else if (valueSpecification instanceof SimpleFunctionExpression) {
        SimpleFunctionExpression sfe = (SimpleFunctionExpression) valueSpecification;
        Function func = (Function) sfe._func();
        if (!canReactivateWithoutJavaCompilationImpl(func, es, atRoot, lambdaOpenVariablesMap, bridge)) {
            throw new PureDynamicReactivateException(valueSpecification.getSourceInformation(), "Can not reactivate function, unexpected:" + func._name());
        }
        RichIterable<?> paramValues = sfe._parametersValues().collect(new org.eclipse.collections.api.block.function.Function<Object, Object>() {

            @Override
            public Object valueOf(Object value) {
                if (value instanceof ValueSpecification) {
                    Object newValue = reactivateWithoutJavaCompilationImpl((ValueSpecification) value, lambdaOpenVariablesMap, es, false, bridge);
                    if (newValue instanceof RichIterable) {
                        return newValue;
                    } else {
                        return Lists.fixedSize.of(newValue);
                    }
                } else {
                    return value;
                }
            }
        });
        MutableList<Object> vars = Lists.mutable.withAll(paramValues);
        if (sfe._func()._name().equals("new_Class_1__String_1__KeyExpression_MANY__T_1_")) {
            // Have to get the first param from the generic type
            vars.set(0, Lists.fixedSize.of(sfe._genericType()._rawType()));
        } else if (sfe._func()._name().equals("cast_Any_m__T_1__T_m_")) {
            // Have to get the second param from the generic type
            vars.set(1, Lists.fixedSize.of(sfe._genericType()));
        }
        return Pure._evaluateToMany(es, bridge, func, vars);
    } else if (valueSpecification instanceof VariableExpression) {
        String varName = ((VariableExpression) valueSpecification)._name();
        if (!lambdaOpenVariablesMap.getMap().containsKey(varName)) {
            throw new PureDynamicReactivateException("Attempt to use out of scope variable: " + varName);
        }
        Object result = lambdaOpenVariablesMap.getMap().get(varName);
        return ((org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List<Object>) result)._values();
    } else {
        throw new PureDynamicReactivateException(valueSpecification.getSourceInformation(), "Unexpected type to dynamically reactivate: " + valueSpecification.getClass().getName());
    }
}
Also used : UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) RoutedValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.router.RoutedValueSpecification) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) CompiledProcessorSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport) NativeFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.NativeFunction) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) RoutedValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.router.RoutedValueSpecification) Pair(org.eclipse.collections.api.tuple.Pair) KeyExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpression) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PureDynamicReactivateException(org.finos.legend.pure.runtime.java.compiled.compiler.PureDynamicReactivateException) RichIterable(org.eclipse.collections.api.RichIterable)

Example 5 with CompiledProcessorSupport

use of org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport in project legend-pure by finos.

the class TestJavaStandaloneLibraryGenerator method testStandaloneLibraryNoExternal.

@Test
public void testStandaloneLibraryNoExternal() throws Exception {
    String metadataName = "test_metadata_name";
    JavaStandaloneLibraryGenerator generator = JavaStandaloneLibraryGenerator.newGenerator(runtime, CompiledExtensionLoader.extensions(), false, null);
    Path classesDir = this.temporaryFolder.newFolder("classes").toPath();
    generator.serializeAndWriteDistributedMetadata(metadataName, classesDir);
    generator.compileAndWriteClasses(classesDir);
    URLClassLoader classLoader = new URLClassLoader(new URL[] { classesDir.toUri().toURL() }, Thread.currentThread().getContextClassLoader());
    MetadataLazy metadataLazy = MetadataLazy.fromClassLoader(classLoader, metadataName);
    CompiledExecutionSupport executionSupport = new CompiledExecutionSupport(new JavaCompilerState(null, classLoader), new CompiledProcessorSupport(classLoader, metadataLazy, null), null, runtime.getCodeStorage(), null, VoidExecutionActivityListener.VOID_EXECUTION_ACTIVITY_LISTENER, new ConsoleCompiled(), new FunctionCache(), new ClassCache(classLoader), null, null);
    String className = JavaPackageAndImportBuilder.getRootPackage() + ".test_standalone_tests";
    Class<?> testClass = classLoader.loadClass(className);
    Method joinWithCommas = testClass.getMethod("Root_test_standalone_joinWithCommas_String_MANY__String_1_", RichIterable.class, ExecutionSupport.class);
    Object result1 = joinWithCommas.invoke(null, Lists.immutable.with("a", "b", "c"), executionSupport);
    Assert.assertEquals("a, b, c", result1);
    Method testWithReflection = testClass.getMethod("Root_test_standalone_testWithReflection_String_1__String_1_", String.class, ExecutionSupport.class);
    Object result2 = testWithReflection.invoke(null, "_*_", executionSupport);
    Assert.assertEquals("_*_testWithReflection", result2);
}
Also used : Path(java.nio.file.Path) JavaCompilerState(org.finos.legend.pure.runtime.java.compiled.compiler.JavaCompilerState) Method(java.lang.reflect.Method) CompiledProcessorSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport) URLClassLoader(java.net.URLClassLoader) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) ClassCache(org.finos.legend.pure.runtime.java.compiled.metadata.ClassCache) JavaStandaloneLibraryGenerator(org.finos.legend.pure.runtime.java.compiled.generation.JavaStandaloneLibraryGenerator) ConsoleCompiled(org.finos.legend.pure.runtime.java.compiled.execution.ConsoleCompiled) MetadataLazy(org.finos.legend.pure.runtime.java.compiled.metadata.MetadataLazy) FunctionCache(org.finos.legend.pure.runtime.java.compiled.metadata.FunctionCache) Test(org.junit.Test)

Aggregations

CompiledProcessorSupport (org.finos.legend.pure.runtime.java.compiled.execution.CompiledProcessorSupport)6 CompiledExecutionSupport (org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NoSuchElementException (java.util.NoSuchElementException)2 JavaCompiler (javax.tools.JavaCompiler)2 MutableMap (org.eclipse.collections.api.map.MutableMap)2 IntObjectMap (org.eclipse.collections.api.map.primitive.IntObjectMap)2 Pair (org.eclipse.collections.api.tuple.Pair)2 PureAssertFailException (org.finos.legend.pure.m3.exception.PureAssertFailException)2 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)2 InvalidFunctionDescriptorException (org.finos.legend.pure.m3.navigation.function.InvalidFunctionDescriptorException)2 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)2 PureException (org.finos.legend.pure.m4.exception.PureException)2 JavaCompilerState (org.finos.legend.pure.runtime.java.compiled.compiler.JavaCompilerState)2 MemoryClassLoader (org.finos.legend.pure.runtime.java.compiled.compiler.MemoryClassLoader)2 MemoryFileManager (org.finos.legend.pure.runtime.java.compiled.compiler.MemoryFileManager)2 PureJavaCompileException (org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompileException)2 PureJavaCompiler (org.finos.legend.pure.runtime.java.compiled.compiler.PureJavaCompiler)2 StringJavaSource (org.finos.legend.pure.runtime.java.compiled.compiler.StringJavaSource)2 ConsoleCompiled (org.finos.legend.pure.runtime.java.compiled.execution.ConsoleCompiled)2