Skip to content

Commit

Permalink
Pure IDE Light: Add support for Pure runtime options
Browse files Browse the repository at this point in the history
  • Loading branch information
aziemchawdhary-gs committed Feb 27, 2024
1 parent 07c0a0a commit 95d7ba3
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
5 changes: 5 additions & 0 deletions legend-pure-ide-light/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
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.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.*;
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 Down Expand Up @@ -105,6 +101,7 @@ public void run(ServerConfiguration configuration, Environment environment) thro
environment.jersey().register(new Activities(pureSession));
environment.jersey().register(new FileManagement(pureSession));
environment.jersey().register(new LifeCycle(pureSession));
environment.jersey().register(new PureRuntimeOptions(pureSession));

environment.jersey().register(new Suggestion(pureSession));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.finos.legend.pure.ide.light.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import org.finos.legend.pure.ide.light.session.PureSession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

@Api(tags = "Pure Runtime Options")
@Path("/pureRuntimeOptions")
public class PureRuntimeOptions
{
private final PureSession pureSession;

public PureRuntimeOptions(PureSession session)
{
this.pureSession = session;
}

@GET
public void setPureRuntimeOption(@PathParam("name") String optionName, @PathParam("value") Boolean value)
{
this.pureSession.setPureRuntimeOption(optionName, value);
}

@GET
public Boolean getPureRuntimeOption(@PathParam("optionName") String optionName)
{
return this.pureSession.getPureRuntimeOption(optionName);
}

@GET
public Response getAllPureRuntimeOptions(@Context HttpServletRequest request, @Context HttpServletResponse response)
{
return Response.ok((StreamingOutput) outputStream ->
{
ObjectMapper om = new ObjectMapper();
outputStream.write(om.writeValueAsBytes(this.pureSession.getAllPureRuntimeOptions()));
outputStream.close();
}).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage;
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.composite.CompositeCodeStorage;
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.welcome.WelcomeCodeStorage;
import org.finos.legend.pure.m3.serialization.runtime.ExecutedTestTracker;
import org.finos.legend.pure.m3.serialization.runtime.Message;
import org.finos.legend.pure.m3.serialization.runtime.PureRuntime;
import org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder;
import org.finos.legend.pure.m3.serialization.runtime.Source;
import org.finos.legend.pure.m3.serialization.runtime.*;
import org.finos.legend.pure.m3.statelistener.VoidExecutionActivityListener;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.m4.coreinstance.SourceInformation;
Expand All @@ -48,6 +44,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
Expand All @@ -69,6 +66,9 @@ public class PureSession
public Message message = new Message("");

public MutableList<RepositoryCodeStorage> repos;
private final Map<String, Boolean> pureRuntimeOptions = new ConcurrentHashMap<>();

private final String PURE_OPTION_PREFIX = "pure.option.";

public PureSession(SourceLocationConfiguration sourceLocationConfiguration, MutableList<RepositoryCodeStorage> repos)
{
Expand All @@ -82,8 +82,26 @@ public PureSession(SourceLocationConfiguration sourceLocationConfiguration, Muta

this.functionExecution = new FunctionExecutionInterpreted(VoidExecutionActivityListener.VOID_EXECUTION_ACTIVITY_LISTENER);

for (String property : System.getProperties().stringPropertyNames())
{
if (property.startsWith(PURE_OPTION_PREFIX))
{
setPureRuntimeOption(property.substring(PURE_OPTION_PREFIX.length()), Boolean.getBoolean(property));
}
}

this.codeStorage = new CompositeCodeStorage(this.repos.toArray(new RepositoryCodeStorage[0]));
this.pureRuntime = new PureRuntimeBuilder(this.codeStorage).withMessage(this.message).setUseFastCompiler(true).build();
this.pureRuntime = new PureRuntimeBuilder(this.codeStorage)
.withMessage(this.message)
.setUseFastCompiler(true)
.withOptions(new RuntimeOptions() {
@Override
public boolean isOptionSet(String name) {
return getPureRuntimeOption(name);
}
})
.build();

this.functionExecution.init(this.pureRuntime, this.message);
this.codeStorage.initialize(this.message);
}
Expand All @@ -103,6 +121,21 @@ public FunctionExecution getFunctionExecution()
return this.functionExecution;
}

public boolean getPureRuntimeOption(String optionName)
{
Boolean value = this.pureRuntimeOptions.get(optionName);
return value != null && value;
}

public Map<String, Boolean> getAllPureRuntimeOptions()
{
return this.pureRuntimeOptions;
}

public void setPureRuntimeOption(String optionName, boolean value)
{
this.pureRuntimeOptions.put(optionName, value);
}
public TestRunner newTestRunner(int testRunId, TestCollection collection)
{
TestRunnerWrapper testRunnerWrapper = new TestRunnerWrapper(collection, this.getPureRuntime().executedTestTracker);
Expand Down

0 comments on commit 95d7ba3

Please sign in to comment.