Search in sources :

Example 1 with PureCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage 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 PureCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage 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 PureCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage in project legend-pure by finos.

the class TestJavaStandaloneLibraryGenerator method setUp.

@BeforeClass
public static void setUp() {
    MutableCodeStorage codeStorage = new PureCodeStorage(null, new ClassLoaderCodeStorage(CodeRepository.newPlatformCodeRepository()), new EmptyCodeStorage(new GenericCodeRepository("test", "test::.*", PlatformCodeRepository.NAME)));
    setUpRuntime(codeStorage, codeStorage.getAllRepositories(), Tuples.pair("/test/standalone/tests.pure", "import test::standalone::*;\n" + "\n" + "Enum test::standalone::TestEnumeration\n" + "{\n" + "    TYPE1, TYPE2, TYPE3\n" + "}\n" + "\n" + "Class test::standalone::TestClassA\n" + "{\n" + "    name : String[1];\n" + "}\n" + "\n" + "Class test::standalone::TestClassB\n" + "{\n" + "    id:Integer[1];\n" + "    type:TestEnumeration[1];\n" + "}\n" + "\n" + "Association test::standalone::TestAssociation\n" + "{\n" + "    toA:TestClassA[1];\n" + "    toB:TestClassB[1];\n" + "}\n" + "\n" + "function <<access.externalizable>> test::standalone::joinWithCommas(strings:String[*]):String[1]\n" + "{\n" + "    $strings->joinStrings(', ');\n" + "}\n" + "\n" + "function <<access.externalizable>> test::standalone::testWithReflection(prefix:String[1]):String[1]\n" + "{\n" + "    let f = testWithReflection_String_1__String_1_;\n" + "    let class = TestClassA;\n" + "    let association = TestAssociation;\n" + "    let b = ^TestClassB(id=43, type=TestEnumeration.TYPE3, toA=^TestClassA(name=$prefix));\n" + "    if($class == $association, |'ERROR', |$b.toA.name + $f.functionName->toOne());\n" + "}\n"));
}
Also used : EmptyCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.EmptyCodeStorage) MutableCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) GenericCodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.GenericCodeRepository) BeforeClass(org.junit.BeforeClass)

Example 4 with PureCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage in project legend-pure by finos.

the class TestCoreCompiledStateIntegrity method initialize.

@BeforeClass
public static void initialize() {
    MutableCodeStorage codeStorage = new PureCodeStorage(null, new ClassLoaderCodeStorage(Lists.mutable.with(CodeRepository.newPlatformCodeRepository()).withAll(CodeRepositoryProviderHelper.findCodeRepositories())));
    initialize(codeStorage);
}
Also used : MutableCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage) ClassLoaderCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) BeforeClass(org.junit.BeforeClass)

Example 5 with PureCodeStorage

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

Aggregations

PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)22 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)19 Test (org.junit.Test)10 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)9 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)8 CodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)6 MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)6 GenericCodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.GenericCodeRepository)4 PureException (org.finos.legend.pure.m4.exception.PureException)4 BeforeClass (org.junit.BeforeClass)4 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)3 RepositoryCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage)3 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 RichIterable (org.eclipse.collections.api.RichIterable)2 Lists (org.eclipse.collections.api.factory.Lists)2