use of org.finos.legend.pure.m3.serialization.runtime.SourceRegistry 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.SourceRegistry in project legend-pure by finos.
the class ClassLoaderPureGraphCache method buildRepoAndSources.
@Override
public boolean buildRepoAndSources(ModelRepository modelRepository, SourceRegistry sourceRegistry, ParserLibrary parserLibrary, Context context, ProcessorSupport processorSupport, Message message) {
if (this.runtime == null) {
return false;
}
try {
CodeStorage codeStorage = this.runtime.getCodeStorage();
MutableList<String> repoNames = codeStorage.getAllRepoNames().toSortedList(new RepositoryComparator(codeStorage.getAllRepositories()));
PureRepositoryJarLibrary jarLibrary = SimplePureRepositoryJarLibrary.newLibrary(GraphLoader.findJars(repoNames, this.classLoader, message));
GraphLoader loader = new GraphLoader(modelRepository, context, parserLibrary, this.runtime.getIncrementalCompiler().getDslLibrary(), sourceRegistry, null, jarLibrary, this.forkJoinPool);
for (String repoName : repoNames) {
loader.loadRepository(repoName, message);
}
this.state.update(true, -1L, true, null);
return true;
} catch (Exception e) {
modelRepository.clear();
this.state.update(false, -1L, false, e);
return false;
} catch (Error e) {
this.state.update(false, -1L, false, e);
throw e;
}
}
use of org.finos.legend.pure.m3.serialization.runtime.SourceRegistry in project legend-pure by finos.
the class FSGraphLoaderPureGraphCache method buildFromCaches.
@Override
public boolean buildFromCaches(ModelRepository modelRepository, SourceRegistry sources, ParserLibrary library, Context context, ProcessorSupport processorSupport, Message message) {
PureRepositoryJarLibrary jarLibrary = SimplePureRepositoryJarLibrary.newLibraryFromDirectory(getCacheLocation());
final GraphLoader loader = new GraphLoader(modelRepository, context, library, this.pureRuntime.getIncrementalCompiler().getDslLibrary(), sources, null, jarLibrary, this.forkJoinPool);
CodeStorage codeStorage = this.pureRuntime.getCodeStorage();
MutableList<String> repoNames = codeStorage.getAllRepoNames().toSortedList(new RepositoryComparator(codeStorage.getAllRepositories()));
if (shouldAddRootRepo()) {
repoNames.add(ROOT_REPOSITORY_NAME);
}
if (this.allowBuildingFromRepoSubset) {
repoNames.removeIf(new Predicate<String>() {
@Override
public boolean accept(String repoName) {
return !loader.isKnownRepository(repoName);
}
});
}
for (String repoName : repoNames) {
loader.loadRepository(repoName, message);
}
updateCacheState();
return true;
}
use of org.finos.legend.pure.m3.serialization.runtime.SourceRegistry in project legend-pure by finos.
the class MemoryGraphLoaderPureGraphCache method buildFromCaches.
@Override
protected boolean buildFromCaches(ModelRepository modelRepository, SourceRegistry sources, ParserLibrary library, Context context, ProcessorSupport processorSupport, Message message) {
PureRepositoryJarLibrary jarLibrary = SimplePureRepositoryJarLibrary.newLibrary(this.jars);
GraphLoader loader = new GraphLoader(modelRepository, context, library, this.pureRuntime.getIncrementalCompiler().getDslLibrary(), sources, null, jarLibrary, this.forkJoinPool);
loader.loadAll(message);
updateCacheState();
return true;
}
use of org.finos.legend.pure.m3.serialization.runtime.SourceRegistry in project legend-pure by finos.
the class TestBinarySourceSerializer method testSerializationForCurrentRuntime.
private void testSerializationForCurrentRuntime() {
ByteArrayOutputStream serialization = new ByteArrayOutputStream();
BinarySourceSerializer.serialize(serialization, this.runtime.getSourceRegistry());
SourceRegistry sourceRegistry = this.runtime.getSourceRegistry();
MutableIntObjectMap<CoreInstance> instancesById = IntObjectMaps.mutable.empty();
MutableSet<CoreInstance> classifiers = Sets.mutable.empty();
for (Source source : sourceRegistry.getSources()) {
ListIterable<? extends CoreInstance> newInstances = source.getNewInstances();
if (newInstances != null) {
for (CoreInstance instance : newInstances) {
instancesById.put(instance.getSyntheticId(), instance);
classifiers.add(instance.getClassifier());
}
}
}
SourceRegistry targetRegistry = new SourceRegistry(this.runtime.getCodeStorage(), this.runtime.getIncrementalCompiler().getParserLibrary());
Context targetContext = new Context();
BinarySourceSerializer.build(serialization.toByteArray(), targetRegistry, instancesById, this.runtime.getIncrementalCompiler().getParserLibrary(), targetContext);
Assert.assertEquals(sourceRegistry.getSourceIds().toSet(), targetRegistry.getSourceIds().toSet());
for (Source source : sourceRegistry.getSources()) {
Source targetSource = targetRegistry.getSource(source.getId());
Assert.assertEquals(source.getId(), source.getContent(), targetSource.getContent());
Assert.assertEquals(source.getId(), source.isImmutable(), targetSource.isImmutable());
Assert.assertEquals(source.getId(), source.isCompiled(), targetSource.isCompiled());
Assert.assertEquals(getElementsByParserName(source), getElementsByParserName(targetSource));
}
for (CoreInstance classifier : classifiers) {
Assert.assertEquals(PackageableElement.getUserPathForPackageableElement(classifier), this.context.getClassifierInstances(classifier), targetContext.getClassifierInstances(classifier));
}
}
Aggregations