use of org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository in project legend-pure by finos.
the class JavaClassLoaderSourceCodeGenerator method gen.
public static void gen(long start, Path filePath, String name, MutableList<CompiledExtension> extensions) {
RichIterable<CodeRepository> repositoriesForCompilation = Lists.fixedSize.of(CodeRepository.newPlatformCodeRepository());
PureCodeStorage codeStorage = new PureCodeStorage(null, new ClassLoaderCodeStorage(repositoriesForCompilation));
ClassLoaderPureGraphCache graphCache = new ClassLoaderPureGraphCache();
PureRuntime runtime = new PureRuntimeBuilder(codeStorage).withCache(graphCache).setTransactionalByDefault(false).buildAndTryToInitializeFromCache();
if (!runtime.isInitialized()) {
CacheState cacheState = graphCache.getCacheState();
if (cacheState != null) {
String lastStackTrace = cacheState.getLastStackTrace();
if (lastStackTrace != null) {
System.out.println("Cache initialization failure: " + lastStackTrace);
}
}
System.out.println("Initialization from caches failed - compiling from scratch");
runtime.reset();
runtime.loadAndCompileCore();
runtime.loadAndCompileSystem();
}
System.out.format("Finished Pure initialization (%.6fs)%n", (System.nanoTime() - start) / 1_000_000_000.0);
JavaSourceCodeGenerator javaSourceCodeGenerator = new JavaSourceCodeGenerator(runtime.getProcessorSupport(), runtime.getCodeStorage(), true, filePath, false, extensions, name, JavaPackageAndImportBuilder.externalizablePackage());
javaSourceCodeGenerator.generateCode();
javaSourceCodeGenerator.generatePureCoreHelperClasses(new ProcessorContext(runtime.getProcessorSupport(), false));
}
use of org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository in project legend-pure by finos.
the class PureJarMojo method resolveRepositories.
private RichIterable<CodeRepository> resolveRepositories(String[] repositories, String[] excludedRepositories, String[] extraRepositories) {
if (extraRepositories != null) {
RichIterable<CodeRepository> resolvedRepositories = ArrayIterate.collect(extraRepositories, r -> {
try {
return GenericCodeRepository.build(new FileInputStream(r));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
});
PureRepositoriesExternal.addRepositories(resolvedRepositories);
}
RichIterable<CodeRepository> selectedRepos = repositories == null ? PureRepositoriesExternal.repositories() : ArrayIterate.collect(repositories, PureRepositoriesExternal::getRepository);
Set<String> excludedRepositoriesSet = Sets.mutable.of(excludedRepositories == null ? new String[0] : excludedRepositories);
return selectedRepos.select(r -> !excludedRepositoriesSet.contains(r.getName()));
}
use of org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository in project legend-pure by finos.
the class Test_PureTestSuite method getClassLoaderExecutionSupport.
public static CompiledExecutionSupport getClassLoaderExecutionSupport() {
MutableList<CodeRepository> codeRepos = Lists.mutable.of(CodeRepository.newPlatformCodeRepository()).withAll(CodeRepositoryProviderHelper.findCodeRepositories());
ClassLoader classLoader = Test_PureTestSuite.class.getClassLoader();
return new CompiledExecutionSupport(new JavaCompilerState(null, classLoader), new CompiledProcessorSupport(classLoader, MetadataLazy.fromClassLoader(classLoader), Sets.mutable.empty()), null, new PureCodeStorage(null, new ClassLoaderCodeStorage(classLoader, codeRepos)), null, null, new ConsoleCompiled(), new FunctionCache(), new ClassCache(classLoader), null, Sets.mutable.empty());
}
use of org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository in project legend-pure by finos.
the class RepositoryPackageValidator method run.
@Override
public void run(CoreInstance instance, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
PackageableElement packageableElement = PackageableElementCoreInstanceWrapper.toPackageableElement(instance);
SourceInformation sourceInfo = packageableElement.getSourceInformation();
if (sourceInfo != null) {
checkValidPackage(packageableElement._package(), sourceInfo);
String sourceId = sourceInfo.getSourceId();
String repoName = PureCodeStorage.getSourceRepoName(sourceId);
if (repoName != null) {
CodeRepository repo = ((ValidatorState) state).getCodeStorage().getRepository(repoName);
if (repo != null) {
if (!(packageableElement instanceof Package) && !(packageableElement instanceof ImportGroup)) {
Package pkg = packageableElement._package();
if (pkg != null) {
String pkgName = org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(pkg);
if (!repo.isPackageAllowed(pkgName)) {
throw new PureCompilationException(sourceInfo, "Package " + pkgName + " is not allowed in " + repoName + "; only packages matching " + repo.getAllowedPackagesPattern().toString() + " are allowed");
}
}
}
}
}
}
}
use of org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository in project legend-pure by finos.
the class Visibility method isVisibleInRepository.
/**
* Return whether the given instance is visible in the
* given repository. This is true if the repository
* the instance is defined in is visible to the given
* repository. It is also true if the given repository
* is null.
*
* @param instance Pure instance
* @param repository repository
* @param processorSupport processor support
* @return whether instance is visible in repository
*/
private static boolean isVisibleInRepository(CoreInstance instance, CodeRepository repository, RichIterable<CodeRepository> codeRepositories, ProcessorSupport processorSupport) {
if (codeRepositories == null || repository == null) {
return true;
}
// Packages must be handled specially since they are not defined in a source
if (processorSupport.instance_instanceOf(instance, M3Paths.Package)) {
String packagePath = PackageableElement.getUserPathForPackageableElement(instance, "::");
if (M3Paths.Root.equals(packagePath)) {
return true;
}
for (CodeRepository repo : PureCodeStorage.getVisibleRepositories(codeRepositories, repository)) {
if (repo.isPackageAllowed(packagePath)) {
return true;
}
}
return false;
}
SourceInformation sourceInfo = instance.getSourceInformation();
if (sourceInfo == null) {
throw new RuntimeException("Cannot test visibility for an instance with no source information: " + instance);
}
String instanceRepositoryName = PureCodeStorage.getSourceRepoName(sourceInfo.getSourceId());
if (instanceRepositoryName == null) {
return false;
}
CodeRepository instanceRepository = codeRepositories.select(r -> r.getName().equals(instanceRepositoryName)).getFirst();
return (instanceRepository != null) && repository.isVisible(instanceRepository);
}
Aggregations