Search in sources :

Example 1 with Runtime

use of org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime in project legend-pure by finos.

the class M3CoreInstanceGenerator method main.

public static void main(String[] args) {
    String outputDir = args[0];
    String factoryNamePrefix = args[1];
    String fileNameStr = args[2];
    ListIterable<String> filePaths = StringIterate.tokensToList(fileNameStr, ",");
    PureRuntime runtime = new PureRuntimeBuilder(new PureCodeStorage(Paths.get(""), new ClassLoaderCodeStorage(CodeRepository.newPlatformCodeRepository()))).setTransactionalByDefault(false).build();
    ModelRepository repository = runtime.getModelRepository();
    runtime.loadAndCompileCore();
    M3ToJavaGenerator m3ToJavaGenerator = generator(outputDir, factoryNamePrefix, repository);
    m3ToJavaGenerator.generate(repository, filePaths);
}
Also used : ModelRepository(org.finos.legend.pure.m4.ModelRepository) PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)

Example 2 with Runtime

use of org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime in project legend-pure by finos.

the class JavaClassLoaderSourceCodeGenerator method gen.

public static void gen(long start, Path filePath, String name, MutableList<CompiledExtension> extensions) {
    RichIterable<CodeRepository> repositoriesForCompilation = Lists.fixedSize.of(CodeRepository.newPlatformCodeRepository());
    PureCodeStorage codeStorage = new PureCodeStorage(null, new ClassLoaderCodeStorage(repositoriesForCompilation));
    ClassLoaderPureGraphCache graphCache = new ClassLoaderPureGraphCache();
    PureRuntime runtime = new PureRuntimeBuilder(codeStorage).withCache(graphCache).setTransactionalByDefault(false).buildAndTryToInitializeFromCache();
    if (!runtime.isInitialized()) {
        CacheState cacheState = graphCache.getCacheState();
        if (cacheState != null) {
            String lastStackTrace = cacheState.getLastStackTrace();
            if (lastStackTrace != null) {
                System.out.println("Cache initialization failure: " + lastStackTrace);
            }
        }
        System.out.println("Initialization from caches failed - compiling from scratch");
        runtime.reset();
        runtime.loadAndCompileCore();
        runtime.loadAndCompileSystem();
    }
    System.out.format("Finished Pure initialization (%.6fs)%n", (System.nanoTime() - start) / 1_000_000_000.0);
    JavaSourceCodeGenerator javaSourceCodeGenerator = new JavaSourceCodeGenerator(runtime.getProcessorSupport(), runtime.getCodeStorage(), true, filePath, false, extensions, name, JavaPackageAndImportBuilder.externalizablePackage());
    javaSourceCodeGenerator.generateCode();
    javaSourceCodeGenerator.generatePureCoreHelperClasses(new ProcessorContext(runtime.getProcessorSupport(), false));
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository) ClassLoaderPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.ClassLoaderPureGraphCache) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) CacheState(org.finos.legend.pure.m3.serialization.runtime.cache.CacheState) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)

Example 3 with Runtime

use of org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime in project legend-pure by finos.

the class TestGraphIsSerialized method testInitializedFromGraphLoaderSerialization.

@Test
public void testInitializedFromGraphLoaderSerialization() {
    PureRuntime runtime = new PureRuntimeBuilder(getCodeStorage()).buildAndInitialize();
    PureGraphCache cache = new MemoryGraphLoaderPureGraphCache();
    cache.setPureRuntime(runtime);
    cache.cacheRepoAndSources();
    runtime = new PureRuntimeBuilder(getCodeStorage()).withCache(cache).buildAndTryToInitializeFromCache();
    new FunctionExecutionCompiledBuilder().build().init(runtime, new Message(""));
    Assert.assertTrue(cache.getCacheState().getLastStackTrace(), runtime.isInitialized());
    assertAllInstancesMarkedSerialized(runtime);
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) FunctionExecutionCompiledBuilder(org.finos.legend.pure.runtime.java.compiled.execution.FunctionExecutionCompiledBuilder) Message(org.finos.legend.pure.m3.serialization.runtime.Message) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.PureGraphCache) MemoryPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryPureGraphCache) MemoryGraphLoaderPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryGraphLoaderPureGraphCache) MemoryGraphLoaderPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryGraphLoaderPureGraphCache) Test(org.junit.Test)

Example 4 with Runtime

use of org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime in project legend-pure by finos.

the class TestGraphIsSerialized method testInitializedFromM4Serialization.

@Test
public void testInitializedFromM4Serialization() {
    PureRuntime runtime = new PureRuntimeBuilder(getCodeStorage()).buildAndInitialize();
    PureGraphCache cache = new MemoryPureGraphCache();
    cache.setPureRuntime(runtime);
    cache.cacheRepoAndSources();
    runtime = new PureRuntimeBuilder(getCodeStorage()).withCache(cache).buildAndTryToInitializeFromCache();
    new FunctionExecutionCompiledBuilder().build().init(runtime, new Message(""));
    Assert.assertTrue(cache.getCacheState().getLastStackTrace(), runtime.isInitialized());
    assertAllInstancesMarkedSerialized(runtime);
}
Also used : PureRuntime(org.finos.legend.pure.m3.serialization.runtime.PureRuntime) FunctionExecutionCompiledBuilder(org.finos.legend.pure.runtime.java.compiled.execution.FunctionExecutionCompiledBuilder) Message(org.finos.legend.pure.m3.serialization.runtime.Message) MemoryPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryPureGraphCache) PureRuntimeBuilder(org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder) PureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.PureGraphCache) MemoryPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryPureGraphCache) MemoryGraphLoaderPureGraphCache(org.finos.legend.pure.m3.serialization.runtime.cache.MemoryGraphLoaderPureGraphCache) Test(org.junit.Test)

Example 5 with Runtime

use of org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime in project legend-pure by finos.

the class TestMilestonedPropertyUsageInFunctionExpressions method testAllVersionsInRangePropertyUsageForCrossTemporal.

@ToFix
@Ignore
@Test
public void testAllVersionsInRangePropertyUsageForCrossTemporal() {
    runtime.createInMemorySource("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.businesstemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.processingtemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.allVersionsInRange(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    runtime.compile();
    runtime.modify("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.bitemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.businesstemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.all(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    runtime.compile();
    runtime.modify("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.bitemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.processingtemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.all(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    runtime.compile();
    runtime.modify("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.businesstemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.bitemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.allVersionsInRange(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    PureCompilationException e1 = Assert.assertThrows(PureCompilationException.class, runtime::compile);
    Assert.assertEquals("Compilation error at (resource:test.pure line:10 column:55), \"The system can't find a match for the function: classificationAllVersionsInRange(_:Product[1],_:StrictDate[1],_:StrictDate[1])", e1.getMessage());
    runtime.modify("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.processingtemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.bitemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.allVersionsInRange(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    PureCompilationException e2 = Assert.assertThrows(PureCompilationException.class, runtime::compile);
    Assert.assertEquals("Compilation error at (resource:test.pure line:10 column:55), \"The system can't find a match for the function: classificationAllVersionsInRange(_:Product[1],_:StrictDate[1],_:StrictDate[1])", e2.getMessage());
    runtime.modify("test.pure", "import meta::test::milestoning::domain::*;\n" + "Class <<temporal.processingtemporal>> meta::test::milestoning::domain::Product{\n" + "   classification : Classification[*];\n" + "}\n" + "Class  <<temporal.businesstemporal>> meta::test::milestoning::domain::Classification{\n" + "   exchangeName : String[0..1];\n" + "}\n" + "function go():Any[*]\n" + "{\n" + "   {|Product.allVersionsInRange(%2018-1-1, %2018-1-9).classificationAllVersionsInRange(%2018-1-1, %2018-1-9)}\n" + "}\n");
    runtime.compile();
}
Also used : PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) Ignore(org.junit.Ignore) Test(org.junit.Test) ToFix(org.finos.legend.pure.m3.tools.test.ToFix)

Aggregations

Test (org.junit.Test)23 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)16 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)15 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)14 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)14 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)14 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)9 RuntimeTestScriptBuilder (org.finos.legend.pure.m3.RuntimeTestScriptBuilder)9 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)9 Message (org.finos.legend.pure.m3.serialization.runtime.Message)8 List (java.util.List)7 ListIterate (org.eclipse.collections.impl.utility.ListIterate)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 Lists (org.eclipse.collections.impl.factory.Lists)6 MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 Set (java.util.Set)5 MutableList (org.eclipse.collections.api.list.MutableList)5 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)5