Search in sources :

Example 1 with MutableCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage 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 2 with MutableCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage 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 3 with MutableCodeStorage

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

the class FileManagement method dir.

@GET
@Path("dir")
public Response dir(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    return Response.ok((StreamingOutput) outStream -> {
        response.setContentType("application/json");
        String path = request.getParameter("parameters");
        StringBuilder json = new StringBuilder("[");
        MutableList<CodeStorageNode> nodes = LazyIterate.reject(pureSession.getCodeStorage().getFiles(path), IGNORED_NODE).toSortedList(NODE_COMPARATOR);
        if ("/".equals(path)) {
            nodes.sortThis((o1, o2) -> {
                String name1 = PureCodeStorage.WELCOME_FILE_NAME.equals(o1.getName()) || PlatformCodeRepository.NAME.equals(o1.getName()) || ScratchCodeRepository.NAME.equals(o1.getName()) ? "zzz" + o1.getName() : o1.getName();
                String name2 = PureCodeStorage.WELCOME_FILE_NAME.equals(o2.getName()) || PlatformCodeRepository.NAME.equals(o2.getName()) || ScratchCodeRepository.NAME.equals(o2.getName()) ? "zzz" + o2.getName() : o2.getName();
                return name1.compareTo(name2);
            });
        }
        ;
        if (nodes.notEmpty()) {
            MutableCodeStorage codeStorage = pureSession.getCodeStorage();
            Iterator<CodeStorageNode> iterator = nodes.iterator();
            writeNode(json, codeStorage, path, iterator.next());
            while (iterator.hasNext()) {
                json.append(',');
                writeNode(json, codeStorage, path, iterator.next());
            }
        }
        json.append(']');
        outStream.write(json.toString().getBytes(), 0, json.length());
        outStream.close();
    }).build();
}
Also used : MutableCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage) StreamingOutput(javax.ws.rs.core.StreamingOutput) CodeStorageNode(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorageNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with MutableCodeStorage

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

the class Source method refreshContent.

public boolean refreshContent() {
    if (isImmutable() || isInMemory()) {
        return false;
    }
    synchronized (this.lock) {
        MutableCodeStorage codeStorage = this.sourceRegistry.getCodeStorage();
        if (codeStorage.exists(this.id)) {
            String currentContent = this.content;
            String contentFromStorage = codeStorage.getContentAsText(this.id);
            if (currentContent.equals(contentFromStorage)) {
                return false;
            }
            String oldContent = this.content;
            this.content = (contentFromStorage == null) ? "" : contentFromStorage;
            this.sourceRegistry.getSourceEventHandlers().forEach(eh -> eh.updateSource(this, oldContent));
            unCompile();
        } else {
            this.sourceRegistry.unregisterSource(this.id);
            this.sourceRegistry.getSourceEventHandlers().forEach(eh -> eh.deleteSource(this));
        }
        return true;
    }
}
Also used : MutableCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)

Example 5 with MutableCodeStorage

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

the class PureRuntime method loadAndCompile.

public void loadAndCompile(Iterable<String> paths) {
    this.pureRuntimeStatus.startLoadingAndCompilingSystemFiles();
    MutableList<Source> sources = Lists.mutable.with();
    MutableCodeStorage codeStorage = getCodeStorage();
    for (String path : paths) {
        codeStorage.getFileOrFiles(path).collect(this.loadSource, sources);
    }
    compile(sources);
    this.pureRuntimeStatus.finishedLoadingAndCompilingSystemFiles();
}
Also used : MutableCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)

Aggregations

MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)18 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)5 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)5 BeforeClass (org.junit.BeforeClass)5 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)4 CodeStorageNode (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorageNode)3 EmptyCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.EmptyCodeStorage)2 Message (org.finos.legend.pure.m3.serialization.runtime.Message)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Log (org.apache.maven.plugin.logging.Log)1 RichIterable (org.eclipse.collections.api.RichIterable)1 Predicate (org.eclipse.collections.api.block.predicate.Predicate)1 Lists (org.eclipse.collections.api.factory.Lists)1