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();
}
}
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);
}
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));
}
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);
}
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);
}
Aggregations