Search in sources :

Example 1 with SourceRegistry

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

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;
    }
}
Also used : CodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorage) GraphLoader(org.finos.legend.pure.m3.serialization.runtime.GraphLoader) RepositoryComparator(org.finos.legend.pure.m3.serialization.runtime.RepositoryComparator) SimplePureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.SimplePureRepositoryJarLibrary) PureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.PureRepositoryJarLibrary)

Example 3 with SourceRegistry

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;
}
Also used : PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) CodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorage) GraphLoader(org.finos.legend.pure.m3.serialization.runtime.GraphLoader) RepositoryComparator(org.finos.legend.pure.m3.serialization.runtime.RepositoryComparator) SimplePureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.SimplePureRepositoryJarLibrary) PureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.PureRepositoryJarLibrary)

Example 4 with SourceRegistry

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;
}
Also used : GraphLoader(org.finos.legend.pure.m3.serialization.runtime.GraphLoader) SimplePureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.SimplePureRepositoryJarLibrary) PureRepositoryJarLibrary(org.finos.legend.pure.m3.serialization.runtime.binary.PureRepositoryJarLibrary)

Example 5 with SourceRegistry

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));
    }
}
Also used : Context(org.finos.legend.pure.m3.compiler.Context) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

GraphLoader (org.finos.legend.pure.m3.serialization.runtime.GraphLoader)3 PureRepositoryJarLibrary (org.finos.legend.pure.m3.serialization.runtime.binary.PureRepositoryJarLibrary)3 SimplePureRepositoryJarLibrary (org.finos.legend.pure.m3.serialization.runtime.binary.SimplePureRepositoryJarLibrary)3 CodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorage)2 RepositoryComparator (org.finos.legend.pure.m3.serialization.runtime.RepositoryComparator)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IntSet (org.eclipse.collections.api.set.primitive.IntSet)1 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)1 Context (org.finos.legend.pure.m3.compiler.Context)1 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)1 Source (org.finos.legend.pure.m3.serialization.runtime.Source)1 SourceRegistry (org.finos.legend.pure.m3.serialization.runtime.SourceRegistry)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1