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