Skip to content

Commit

Permalink
Support PureIdeLight to spin up with subset of available repositories (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>

* Update legend-pure-ide-light/src/main/java/org/finos/legend/pure/ide/light/PureIDEServer.java

Co-authored-by: Kevin Knight <[email protected]>

* Add missing imports

---------

Co-authored-by: Kevin Knight <[email protected]>
  • Loading branch information
hardikmaheshwari and kevin-m-knight-gs authored Oct 4, 2023
1 parent 4d55632 commit ea0f5bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,14 +45,15 @@
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;

import javax.servlet.DispatcherType;
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<ServerConfiguration>
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -125,14 +130,25 @@ private void enableCors(Environment environment)
corsFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*");
}

private MutableList<RepositoryCodeStorage> getRepositories(SourceLocationConfiguration sourceLocationConfiguration)
private MutableList<RepositoryCodeStorage> getRepositories(SourceLocationConfiguration sourceLocationConfiguration, List<String> requiredRepositories)
{
MutableList<RepositoryCodeStorage> fromIde = this.buildRepositories(sourceLocationConfiguration);
Set<String> fromIdeName = fromIde.flatCollect(RepositoryCodeStorage::getAllRepositories).collect(CodeRepository::getName).toSet();
List<CodeRepository> fromClasspath = CodeRepositoryProviderHelper.findCodeRepositories()
.toList()
.reject(x -> fromIdeName.contains(x.getName()));
return fromIde.with(new ClassLoaderCodeStorage(fromClasspath));
Map<CodeRepository, RepositoryCodeStorage> 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<String> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import io.dropwizard.Configuration;
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;

import java.util.List;

@JsonIgnoreProperties(
ignoreUnknown = true
)
public class ServerConfiguration extends Configuration
{
public SwaggerBundleConfiguration swagger;
public SourceLocationConfiguration sourceLocationConfiguration;
public List<String> requiredRepositories;
}

0 comments on commit ea0f5bf

Please sign in to comment.