Search in sources :

Example 1 with PureRuntime

use of org.finos.legend.pure.m3.serialization.runtime.PureRuntime in project legend-pure by finos.

the class SourceMutation method perform.

public void perform(PureRuntime pureRuntime) {
    if (this.lineRangesToRemoveByFile.notEmpty()) {
        SourceRegistry sourceRegistry = pureRuntime.getSourceRegistry();
        for (String sourceId : this.lineRangesToRemoveByFile.keysView()) {
            IntSet set = calculateLinesToRemove(this.lineRangesToRemoveByFile.get(sourceId));
            Source source = sourceRegistry.getSource(sourceId);
            if (source == null) {
                throw new RuntimeException("Unknown source: " + sourceId);
            }
            String file = source.getContent();
            String[] lines = LINE_SPLITTER.split(file);
            StringBuilder buffer = new StringBuilder(file.length());
            for (int i = 0; i < lines.length; i++) {
                if (!set.contains(i + 1)) {
                    buffer.append(lines[i]);
                }
            }
            pureRuntime.modify(sourceId, buffer.toString());
        }
        pureRuntime.compile();
    }
}
Also used : SourceRegistry(org.finos.legend.pure.m3.serialization.runtime.SourceRegistry) IntSet(org.eclipse.collections.api.set.primitive.IntSet) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Source(org.finos.legend.pure.m3.serialization.runtime.Source)

Example 2 with PureRuntime

use of org.finos.legend.pure.m3.serialization.runtime.PureRuntime 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 3 with PureRuntime

use of org.finos.legend.pure.m3.serialization.runtime.PureRuntime 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 4 with PureRuntime

use of org.finos.legend.pure.m3.serialization.runtime.PureRuntime 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 5 with PureRuntime

use of org.finos.legend.pure.m3.serialization.runtime.PureRuntime 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)

Aggregations

PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)23 Test (org.junit.Test)15 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)14 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)14 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)14 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)13 Source (org.finos.legend.pure.m3.serialization.runtime.Source)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 Message (org.finos.legend.pure.m3.serialization.runtime.Message)9 CodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)6 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)5 PureException (org.finos.legend.pure.m4.exception.PureException)5 IOException (java.io.IOException)4 MutableList (org.eclipse.collections.api.list.MutableList)4 SetIterable (org.eclipse.collections.api.set.SetIterable)4 MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)4 PureGraphCache (org.finos.legend.pure.m3.serialization.runtime.cache.PureGraphCache)4 FunctionExecutionCompiledBuilder (org.finos.legend.pure.runtime.java.compiled.execution.FunctionExecutionCompiledBuilder)4 Set (java.util.Set)3 Path (javax.ws.rs.Path)3