From ea0f5bfdb6c73b3667908a851025eff506472936 Mon Sep 17 00:00:00 2001 From: Hardik Maheshwari <19693874+hardikmaheshwari@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:59:27 +0530 Subject: [PATCH] Support PureIdeLight to spin up with subset of available repositories (#734) * Make PureIdeLight configurable to spin up with a repository and its dependencies * Update legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java Co-authored-by: Kevin Knight <57677197+kevin-m-knight-gs@users.noreply.github.com> * Update legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java Co-authored-by: Kevin Knight <57677197+kevin-m-knight-gs@users.noreply.github.com> * Add missing imports --------- Co-authored-by: Kevin Knight <57677197+kevin-m-knight-gs@users.noreply.github.com> --- .../legend/pure/ide/light/PureIDEServer.java | 36 +++++++++++++------ .../pure/ide/light/ServerConfiguration.java | 3 ++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java b/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java index a4e1f4e2c0..e2fce0df68 100644 --- a/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java +++ b/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java @@ -21,13 +21,17 @@ import io.federecio.dropwizard.swagger.SwaggerBundle; import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import io.federecio.dropwizard.swagger.SwaggerResource; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.factory.Maps; +import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.api.set.MutableSet; import org.eclipse.jetty.servlets.CrossOriginFilter; import org.finos.legend.pure.ide.light.api.Activities; -import org.finos.legend.pure.ide.light.api.Suggestion; import org.finos.legend.pure.ide.light.api.FileManagement; import org.finos.legend.pure.ide.light.api.LifeCycle; import org.finos.legend.pure.ide.light.api.Service; +import org.finos.legend.pure.ide.light.api.Suggestion; import org.finos.legend.pure.ide.light.api.concept.Concept; import org.finos.legend.pure.ide.light.api.concept.MovePackageableElements; import org.finos.legend.pure.ide.light.api.concept.RenameConcept; @@ -41,6 +45,7 @@ import org.finos.legend.pure.ide.light.session.PureSession; import org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository; import org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepositoryProviderHelper; +import org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepositorySet; import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage; import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage; @@ -48,7 +53,7 @@ import javax.servlet.FilterRegistration; import java.util.EnumSet; import java.util.List; -import java.util.Set; +import java.util.Map; public abstract class PureIDEServer extends Application { @@ -81,7 +86,7 @@ public void run(ServerConfiguration configuration, Environment environment) thro (configuration.swagger.getContextRoot().endsWith("/") ? "" : "/") + "api") ); - this.pureSession = new PureSession(configuration.sourceLocationConfiguration, this.getRepositories(configuration.sourceLocationConfiguration)); + this.pureSession = new PureSession(configuration.sourceLocationConfiguration, this.getRepositories(configuration.sourceLocationConfiguration, configuration.requiredRepositories)); environment.jersey().register(new Concept(pureSession)); environment.jersey().register(new RenameConcept(pureSession)); @@ -125,14 +130,25 @@ private void enableCors(Environment environment) corsFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*"); } - private MutableList getRepositories(SourceLocationConfiguration sourceLocationConfiguration) + private MutableList getRepositories(SourceLocationConfiguration sourceLocationConfiguration, List requiredRepositories) { - MutableList fromIde = this.buildRepositories(sourceLocationConfiguration); - Set fromIdeName = fromIde.flatCollect(RepositoryCodeStorage::getAllRepositories).collect(CodeRepository::getName).toSet(); - List fromClasspath = CodeRepositoryProviderHelper.findCodeRepositories() - .toList() - .reject(x -> fromIdeName.contains(x.getName())); - return fromIde.with(new ClassLoaderCodeStorage(fromClasspath)); + Map repoToCodeStorageMap = Maps.mutable.empty(); + repoToCodeStorageMap.putAll(CodeRepositoryProviderHelper.findCodeRepositories().toMap(r -> r, ClassLoaderCodeStorage::new)); + repoToCodeStorageMap.putAll(this.buildRepositories(sourceLocationConfiguration).toMap(cs -> cs.getAllRepositories().getOnly(), cs -> cs)); + + CodeRepositorySet codeRepositorySet = CodeRepositorySet.newBuilder().withCodeRepositories(repoToCodeStorageMap.keySet()).build(); + + if (requiredRepositories != null) + { + MutableSet requiredSet = Sets.mutable.withAll(requiredRepositories); + if (codeRepositorySet.hasRepository("pure_ide")) + { + requiredSet.add("pure_ide"); + } + codeRepositorySet = codeRepositorySet.subset(requiredSet); + } + + return codeRepositorySet.getRepositories().collect(repoToCodeStorageMap::get, Lists.mutable.ofInitialCapacity(codeRepositorySet.size())); } public PureSession getPureSession() diff --git a/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/ServerConfiguration.java b/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/ServerConfiguration.java index c3f9b385b1..63a4ea15cd 100644 --- a/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/ServerConfiguration.java +++ b/legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/ServerConfiguration.java @@ -18,6 +18,8 @@ import io.dropwizard.Configuration; import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; +import java.util.List; + @JsonIgnoreProperties( ignoreUnknown = true ) @@ -25,4 +27,5 @@ public class ServerConfiguration extends Configuration { public SwaggerBundleConfiguration swagger; public SourceLocationConfiguration sourceLocationConfiguration; + public List requiredRepositories; } \ No newline at end of file