use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.EmptyCodeStorage 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.EmptyCodeStorage in project legend-pure by finos.
the class PureJarSerializer method writePureRepositoryJars.
private static void writePureRepositoryJars(Path outputDirectory, Path sourceDirectory, String platformVersion, RichIterable<CodeRepository> repositories, Log log) throws IOException {
SetIterable<CodeRepository> repositoriesForCompilation = PureCodeStorage.getRepositoryDependencies(PureRepositoriesExternal.repositories(), repositories);
PureRuntime runtime;
RichIterable<CodeRepository> repositoriesToSerialize;
if (null == sourceDirectory) {
log.info(" *Building code storage leveraging the class loader (as sourceDirectory is not specified)");
ClassLoaderCodeStorage cs = new ClassLoaderCodeStorage(repositoriesForCompilation);
log.info(" " + cs.getRepositories().collect(CodeRepository::getName) + " - " + cs.getUserFiles().size() + " files");
MutableCodeStorage codeStorage = new PureCodeStorage(null, cs);
Message message = getMessage(log, " ");
log.info(" *Starting file compilation");
runtime = new PureRuntimeBuilder(codeStorage).setTransactionalByDefault(false).buildAndInitialize(message);
repositoriesToSerialize = repositoriesForCompilation;
log.info(" -> Finished compilation");
} else {
log.info(" *Building code storage leveraging the sourceDirectory " + sourceDirectory);
PartitionIterable<CodeRepository> partition = repositories.partition(r -> Files.exists(sourceDirectory.resolve(r.getName())));
RichIterable<CodeRepository> repositoriesWithSource = partition.getSelected();
RichIterable<CodeRepository> repositoriesWithoutSource = partition.getRejected();
// Code Storages
MutableList<AbstractRepositoryCodeStorage> codeStoragesFromSource = Lists.mutable.withAll(repositoriesWithSource.collect(r -> new MutableFSCodeStorage(r, sourceDirectory.resolve(r.getName()))));
MutableList<AbstractRepositoryCodeStorage> allCodeStorage = Lists.mutable.withAll(codeStoragesFromSource).withAll(repositoriesWithoutSource.collect(EmptyCodeStorage::new));
log.info(" *Loading the following repo from PARs: " + repositoriesWithoutSource.collect(CodeRepository::getName));
// Build the runtime
MutableCodeStorage codeStorage = new PureCodeStorage(sourceDirectory, allCodeStorage.toArray(new RepositoryCodeStorage[0]));
runtime = new PureRuntimeBuilder(codeStorage).setTransactionalByDefault(false).build();
// Load the PARS
MutableList<String> namesOfRepoWithoutAvailableSource = repositoriesWithoutSource.collect(CodeRepository::getName).toList();
Message message = getMessage(log, " ");
PureRepositoryJarLibrary jarLibrary = SimplePureRepositoryJarLibrary.newLibrary(GraphLoader.findJars(namesOfRepoWithoutAvailableSource, PureJarSerializer.class.getClassLoader(), message));
final GraphLoader loader = new GraphLoader(runtime.getModelRepository(), runtime.getContext(), runtime.getIncrementalCompiler().getParserLibrary(), runtime.getIncrementalCompiler().getDslLibrary(), runtime.getSourceRegistry(), runtime.getURLPatternLibrary(), jarLibrary);
loader.loadAll(message);
// Compile Sources
log.info(" *Starting file compilation");
codeStoragesFromSource.forEach(r -> log.info(" " + r.getRepositories().collect(CodeRepository::getName) + " - " + r.getUserFiles().size() + " files (from: " + ((FSCodeStorage) r).getRoot() + ")"));
for (CodeRepository repository : repositoriesWithSource) {
Path path = sourceDirectory.resolve(repository.getName());
log.info(" Compiling repository '" + repository.getName() + "' in " + path);
MutableFSCodeStorage fs = new MutableFSCodeStorage(repository, path);
log.info(" Found " + fs.getUserFiles().size() + " files");
runtime.loadAndCompile(new PureCodeStorage(sourceDirectory, fs).getUserFiles());
log.info(" -> Finished compiling repository '" + repository.getName() + "'");
}
repositoriesToSerialize = repositoriesWithSource;
log.info(" -> Finished compilation");
}
Files.createDirectories(outputDirectory);
log.info(" *Starting serialization");
for (String repositoryName : repositoriesToSerialize.collect(CodeRepository::getName)) {
Path outputFile = outputDirectory.resolve("pure-" + repositoryName + "." + ARCHIVE_FILE_EXTENSION);
log.info(" Writing " + outputFile);
try (OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(outputFile))) {
BinaryModelRepositorySerializer.serialize(outputStream, platformVersion, null, repositoryName, runtime);
}
}
}
Aggregations