Skip to content

Commit

Permalink
pure ide: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Nov 4, 2024
1 parent d8bf1ae commit aa7a9ed
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

import io.swagger.annotations.Api;
import org.finos.legend.engine.ide.session.PureSession;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedPropertyInstance;
import org.finos.legend.pure.m3.navigation.Instance;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m3.navigation.M3Properties;
import org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement;
import org.finos.legend.pure.m3.navigation.function.Function;
import org.finos.legend.pure.m3.pct.shared.PCTTools;
import org.finos.legend.pure.m3.serialization.runtime.PureRuntime;
import org.finos.legend.pure.m3.serialization.runtime.Source;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
Expand Down Expand Up @@ -77,24 +78,32 @@ public Response getConceptInfo(@Context HttpServletRequest request, @Context Htt
CoreInstance found = src.navigate(Integer.parseInt(line), Integer.parseInt(column), session.getPureRuntime().getProcessorSupport());
if (found != null)
{
String doc = PCTTools.getDoc(found, pureRuntime.getProcessorSupport());
if (Instance.instanceOf(found, M3Paths.AbstractProperty, session.getPureRuntime().getProcessorSupport()))
{
String path = PackageableElement.getUserPathForPackageableElement(found);
CoreInstance owner = Instance.getValueForMetaPropertyToOneResolved(found, M3Properties.owner, session.getPureRuntime().getProcessorSupport());
String ownerPath = PackageableElement.getUserPathForPackageableElement(owner);
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getValueForMetaPropertyToOne(M3Properties.name).getName() + "\",\"owner\":\"" + ownerPath + "\",\"pureType\":\"" + (found instanceof QualifiedPropertyInstance ? "QualifiedProperty" : "Property") + "\"}").getBytes());
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getValueForMetaPropertyToOne(M3Properties.name).getName() + "\",\"owner\":\"" + ownerPath + "\",\"pureType\":\"" + (found instanceof QualifiedPropertyInstance ? "QualifiedProperty" : "Property") + "\",\"doc\":" + (doc != null ? ("\"" + doc + "\"") : null) + "}").getBytes());
}
else if (Instance.instanceOf(found, M3Paths.Enum, session.getPureRuntime().getProcessorSupport()))
{
String path = PackageableElement.getUserPathForPackageableElement(found);
CoreInstance owner = found.getClassifier();
String ownerPath = PackageableElement.getUserPathForPackageableElement(owner);
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getName() + "\",\"owner\":\"" + ownerPath + "\",\"pureType\":\"Enum\"}").getBytes());
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getName() + "\",\"owner\":\"" + ownerPath + "\",\"pureType\":\"Enum\",\"doc\":" + (doc != null ? ("\"" + doc + "\"") : null) + "}").getBytes());
}
else if (Instance.instanceOf(found, M3Paths.ConcreteFunctionDefinition, session.getPureRuntime().getProcessorSupport()) || Instance.instanceOf(found, M3Paths.NativeFunction, session.getPureRuntime().getProcessorSupport()))
{
String path = PackageableElement.getUserPathForPackageableElement(found);
String grammarDoc = PCTTools.getGrammarDoc(found, pureRuntime.getProcessorSupport());
String grammarChars = PCTTools.getGrammarCharacters(found, pureRuntime.getProcessorSupport());
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getValueForMetaPropertyToOne(M3Properties.functionName).getName() + "\",\"pureType\":\"" + found.getValueForMetaPropertyToOne(M3Properties.classifierGenericType).getValueForMetaPropertyToOne(M3Properties.rawType).getName() + "\",\"test\":" + (PCTTools.isPCTTest(found, pureRuntime.getProcessorSupport()) || PCTTools.isTest(found, pureRuntime.getProcessorSupport())) + ",\"pct\":" + PCTTools.isPCTTest(found, pureRuntime.getProcessorSupport()) + ",\"doc\":" + (doc != null ? ("\"" + doc + "\"") : null) + ",\"grammarDoc\":" + (grammarDoc != null ? ("\"" + grammarDoc + "\"") : null) + ",\"grammarChars\":" + (grammarChars != null ? ("\"" + grammarChars + "\"") : null) + ",\"signature\":\"" + Function.prettyPrint(found, pureRuntime.getProcessorSupport()) + "\"}").getBytes());
}
else
{
String path = PackageableElement.getUserPathForPackageableElement(found);
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + (found instanceof ConcreteFunctionDefinition ? found.getValueForMetaPropertyToOne(M3Properties.functionName).getName() : found.getName()) + "\",\"pureType\":\"" + found.getValueForMetaPropertyToOne(M3Properties.classifierGenericType).getValueForMetaPropertyToOne(M3Properties.rawType).getName() + "\"}").getBytes());
outputStream.write(("{\"path\":\"" + path + "\",\"pureName\":\"" + found.getName() + "\",\"pureType\":\"" + found.getValueForMetaPropertyToOne(M3Properties.classifierGenericType).getValueForMetaPropertyToOne(M3Properties.rawType).getName() + "\",\"doc\":" + (doc != null ? ("\"" + doc + "\"") : null) + "}").getBytes());
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.finos.legend.pure.m3.navigation.M3Properties;
import org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.pct.shared.PCTTools;
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.CodeStorageNode;
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.composite.CompositeCodeStorage;
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.vcs.MutableVersionControlledCodeStorage;
Expand Down Expand Up @@ -71,10 +72,22 @@ public void run(PureSession pureSession, JSONObject extraParams, JSONArray modif
String path = getPath(extraParams);
String[] filterPaths = getFilterPaths(extraParams);
boolean relevantTestsOnly = getRelevantTestsOnly(extraParams);
String pctAdapter = (String) extraParams.get("pctAdapter");
Predicate<? super CoreInstance> filterPredicate = getFilterPredicate(runtime, relevantTestsOnly);
if (pctAdapter != null)
{
filterPredicate = Predicates.and(filterPredicate, new Predicate<CoreInstance>()
{
@Override
public boolean accept(CoreInstance test)
{
return PCTTools.isPCTTest(test, runtime.getProcessorSupport());
}
});
}

TestCollection collection = getTestCollection(pureSession, path, filterPaths, filterPredicate);
TestRunner runner = pureSession.newTestRunner(newId, collection);
TestRunner runner = pureSession.newTestRunner(newId, collection, pctAdapter);

this.executorService.execute(runner);

Expand All @@ -98,6 +111,7 @@ public void run(PureSession pureSession, JSONObject extraParams, JSONArray modif
outputStream.write((",\"path\":\"" + path + "\"").getBytes());
outputStream.write((",\"filterPaths\":" + (filterPaths.length == 0 ? "[]" : ArrayIterate.makeString(filterPaths, "[\"", "\",\"", "\"]"))).getBytes());
outputStream.write((",\"relevantTestsOnly\":" + relevantTestsOnly).getBytes());
outputStream.write((",\"pctAdapter\":\"" + pctAdapter + "\"").getBytes());
outputStream.write(",\"count\":".getBytes());
outputStream.write(Integer.toString(tests.size()).getBytes());
outputStream.write(",\"tests\":".getBytes());
Expand All @@ -116,13 +130,13 @@ public String valueOf(TestNode testNode)

private String getPath(JSONObject extraParams)
{
String path = (String)extraParams.get("path");
String path = (String) extraParams.get("path");
return StringIterate.isEmpty(path) ? "::" : path;
}

private String[] getFilterPaths(JSONObject extraParams)
{
JSONArray filterPaths = (JSONArray)extraParams.get("filterPaths");
JSONArray filterPaths = (JSONArray) extraParams.get("filterPaths");
if (filterPaths != null)
{
String[] paths = new String[filterPaths.size()];
Expand All @@ -134,18 +148,18 @@ private String[] getFilterPaths(JSONObject extraParams)

private boolean getRelevantTestsOnly(JSONObject extraParams)
{
Boolean relevantTestsOnly = (Boolean)extraParams.get("relevantTestsOnly");
Boolean relevantTestsOnly = (Boolean) extraParams.get("relevantTestsOnly");
return (relevantTestsOnly == null) ? false : relevantTestsOnly;
}

private Predicate<? super CoreInstance> getFilterPredicate(PureRuntime runtime, boolean relevantTestsOnly)
{
if (!relevantTestsOnly)
{
return null;
return Predicates.alwaysTrue();
}

final MutableVersionControlledCodeStorage codeStorage = (MutableVersionControlledCodeStorage)runtime.getCodeStorage();
final MutableVersionControlledCodeStorage codeStorage = (MutableVersionControlledCodeStorage) runtime.getCodeStorage();
RichIterable<CodeStorageNode> modifiedUserFiles = codeStorage.getModifiedUserFiles();
if (modifiedUserFiles.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ private int writeResultsJSON(OutputStream stream, RichIterable<SourceCoordinates
}
writeSourceCoordinatesJSON(stream, sourceCoordinates);
count++;
if (count > limit)
if (count >= limit)
{
break;
}
}
stream.write("]}".getBytes());
if (count > limit)
if (count >= limit)
{
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public void setPureRuntimeOption(String optionName, boolean value)
this.pureRuntimeOptions.put(optionName, value);
}

public TestRunner newTestRunner(int testRunId, TestCollection collection)
public TestRunner newTestRunner(int testRunId, TestCollection collection, String pctAdapter)
{
TestRunnerWrapper testRunnerWrapper = new TestRunnerWrapper(collection, this.getPureRuntime().executedTestTracker);
TestRunnerWrapper testRunnerWrapper = new TestRunnerWrapper(collection, this.getPureRuntime().executedTestTracker, pctAdapter);
this.testRunnersById.put(testRunId, testRunnerWrapper);
return testRunnerWrapper.testRunner;
}
Expand Down Expand Up @@ -328,9 +328,9 @@ private class TestRunnerWrapper
private TestRunner testRunner;
private final CallBack callBack;

private TestRunnerWrapper(TestCollection collection, CallBack callBack, final ExecutedTestTracker executedTestTracker)
private TestRunnerWrapper(TestCollection collection, CallBack callBack, final ExecutedTestTracker executedTestTracker, String pctAdapter)
{
this.testRunner = new TestRunner(collection, false, PureSession.this.getFunctionExecution(), callBack)
this.testRunner = new TestRunner(collection, false, PureSession.this.getFunctionExecution(), callBack, pctAdapter)
{
@Override
public void run()
Expand All @@ -346,9 +346,9 @@ public void run()
this.callBack = callBack;
}

private TestRunnerWrapper(TestCollection collection, ExecutedTestTracker executedTestTracker)
private TestRunnerWrapper(TestCollection collection, ExecutedTestTracker executedTestTracker, String pctAdapter)
{
this(collection, new CallBack(), executedTestTracker);
this(collection, new CallBack(), executedTestTracker, pctAdapter);
}

void stopAndClear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function <<access.private>> meta::pure::ide::display_ide(elem:Any[1]):String[1]
|'"/ide/pure/icons/play.png"',
|'"/ide/pure/icons/modelElements/function.png"'
);
'{"li_attr":' + display_ide_attr($f) + ', "id":"'+$p->buildKey()+ '","text":"' + printFunctionSignature($f) + '", "icon":'+$icon+'}';,
'{"li_attr":' + display_ide_attr($f) + ', "id":"'+$p->buildKey()+ '","text":"' + printFunctionSignature($f) + '", "icon":'+$icon+', "test":'+ toString(meta::pure::ide::testing::isTest($f)) + ', "pct":' + toString(meta::pure::ide::testing::isPCT($f)) + '}';,
f:NativeFunction<Any>[1] | '{"li_attr":' + display_ide_attr($f) + ', "id":"'+$p->buildKey()+ '","text":"' + printFunctionSignature($f) + '", "icon":"/ide/pure/icons/modelElements/function_parenthesis.png"}',
e:Enumeration<Any>[1] | '{"li_attr":' + display_ide_attr($e) + ', "id":"'+$p->buildKey()+ '","text":"' + $e->id() + '", "icon":"/ide/pure/icons/modelElements/enumeration.gif"}',
p:PrimitiveType[1] | '{"li_attr":' + display_ide_attr($p) + ', "id":"'+$p->buildKey()+ '","text":"' + $p->id() + '", "icon":"/ide/pure/icons/modelElements/primitive.png"}',
Expand Down Expand Up @@ -230,5 +230,3 @@ function <<access.private>> meta::pure::ide::tacticalDeprecated(element:Package[

($model->isNotEmpty() && $element.package == $model && !$element.name->in(['domain', 'producers', 'external', 'consumers'])) ;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

function meta::pure::ide::testing::getPCTAdapters():Pair<String,String>[*]
{
meta::pure::test::pct::PCT->stereotype('adapter').modelElements->map(fn|
let name = $fn.taggedValues->filter(t|$t.tag.value == 'adapterName')->first().value;
if($name->isEmpty(),|'',|$name->toOne())->pair($fn->cast(@PackageableElement)->elementToPath());
)
}

function meta::pure::ide::testing::isTest(f:FunctionDefinition<Any>[1]):Boolean[1]
{
!$f->cast(@AnnotatedElement).stereotypes->filter(st|$st == test->stereotype('Test') || $st == meta::pure::test::pct::PCT->stereotype('test'))->isEmpty();
}

function meta::pure::ide::testing::isPCT(f:FunctionDefinition<Any>[1]):Boolean[1]
{
!$f->cast(@AnnotatedElement).stereotypes->filter(st|$st == meta::pure::test::pct::PCT->stereotype('test'))->isEmpty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import meta::pure::executionPlan::platformBinding::localBinding::*;
import meta::pure::executionPlan::platformBinding::*;
import meta::pure::test::pct::*;

function <<PCT.adapter>> meta::pure::executionPlan::platformBinding::legendJava::pct::testAdapterForJavaBindingExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
function <<PCT.adapter>> {PCT.adapterName='Java Platform Binding'} meta::pure::executionPlan::platformBinding::legendJava::pct::testAdapterForJavaBindingExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
{
let debug = noDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ import meta::pure::metamodel::relation::*;
import meta::relational::tests::pct::process::*;
import meta::pure::test::pct::*;

function <<PCT.adapter>> meta::relational::tests::pct::testAdapterForRelationalWithH2Execution<X|o>(f:Function<{->X[o]}>[1]):X[o]
function <<PCT.adapter>> {PCT.adapterName='H2'} meta::relational::tests::pct::testAdapterForRelationalWithH2Execution<X|o>(f:Function<{->X[o]}>[1]):X[o]
{
meta::relational::tests::pct::testAdapterForRelationalExecution(
$f,
meta::pure::testConnection::getTestConnection(DatabaseType.H2)
)
}

function <<PCT.adapter>> meta::relational::tests::pct::testAdapterForRelationalWithDuckDBExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
function <<PCT.adapter>> {PCT.adapterName='DuckDB'} meta::relational::tests::pct::testAdapterForRelationalWithDuckDBExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
{
meta::relational::tests::pct::testAdapterForRelationalExecution(
$f,
meta::pure::testConnection::getTestConnection(DatabaseType.DuckDB)
)
}

function <<PCT.adapter>> meta::relational::tests::pct::testAdapterForRelationalWithPostgresExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
function <<PCT.adapter>> {PCT.adapterName='PostgreSQL'} meta::relational::tests::pct::testAdapterForRelationalWithPostgresExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
{
meta::relational::tests::pct::testAdapterForRelationalExecution(
$f,
meta::pure::testConnection::getTestConnection(DatabaseType.Postgres)
)
}

function <<PCT.adapter>> meta::relational::tests::pct::testAdapterForRelationalWithSnowflakeExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
function <<PCT.adapter>> {PCT.adapterName='Snowflake'} meta::relational::tests::pct::testAdapterForRelationalWithSnowflakeExecution<X|o>(f:Function<{->X[o]}>[1]):X[o]
{
meta::relational::tests::pct::testAdapterForRelationalExecution(
$f,
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@

<properties>
<!-- Legend -->
<legend.pure.version>5.21.0</legend.pure.version>
<legend.pure.version>5.21.1</legend.pure.version>
<legend.shared.version>0.25.7</legend.shared.version>
<legend.web-application.version>12.54.0</legend.web-application.version>
<legend.web-application.version>12.59.0</legend.web-application.version>

<!-- SONAR -->
<sonar.projectKey>legend-engine</sonar.projectKey>
Expand Down

0 comments on commit aa7a9ed

Please sign in to comment.