Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/demos/web/angular-mo…
Browse files Browse the repository at this point in the history
…del-browser/webpack-dev-middleware-5.3.4
  • Loading branch information
danielratiu authored Jun 12, 2024
2 parents 1a01b63 + 022eba2 commit 1c89276
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 34 deletions.
6 changes: 3 additions & 3 deletions demos/web/angular-model-browser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions demos/web/model-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mps-cli-gradle-plugin/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This Gradle plugin contributes the following tasks:
- `modifiedFiles` - list of paths to modified files - models, modules, root nodes, etc. (either set this input or 'referenceBranchName')
- `referenceBranchName` - the current git working tree and the commits since branching off this branch will be considered (either set this input or 'modifiedFiles')
- Outputs:
- `affectedModels` - list of models affected by modified files. If any of the modified files were moved or deleted then this is `null`.
- `affectedSolutions` - list of modules affected by the modified files. This contains the modules of the modified models and the modules dependent on them
- `affectedSolutionsAndUpstreamDependencies` - list of affected modules and all their dependencies

Expand Down
2 changes: 1 addition & 1 deletion mps-cli-gradle-plugin/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {

// Project versions
ext.major = '0'
ext.minor = '16'
ext.minor = '17'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ConeOfInfluenceComputerTest extends TestBase {
doLast {
def affectedSolutions = computeConeOfInfluence.affectedSolutions
println "all affected solutions: \${affectedSolutions.collect { it.name }.sort()}"
def affectedModels = computeConeOfInfluence.affectedModels
println "all affected models: \${affectedModels.collect { it.name }.sort()}"
}
}
"""
Expand All @@ -42,6 +44,7 @@ class ConeOfInfluenceComputerTest extends TestBase {

then:
result.output.contains twoExpectedSolutions()
result.output.contains "all affected models: []"
}

def "based on a modified root node in a model imported from other"() {
Expand All @@ -56,6 +59,7 @@ class ConeOfInfluenceComputerTest extends TestBase {
then:
result.output.contains "Computing cone of influence based on models."
result.output.contains twoExpectedSolutions()
result.output.contains "all affected models: [mps.cli.lanuse.library_second.library_top, mps.cli.lanuse.library_top.authors_top, mps.cli.lanuse.library_top.library_top]"
}

def "based on a modified root node in a model not imported from other"() {
Expand All @@ -70,6 +74,7 @@ class ConeOfInfluenceComputerTest extends TestBase {
then:
result.output.contains "Computing cone of influence based on models."
result.output.contains "all affected solutions: [mps.cli.lanuse.library_top]"
result.output.contains "all affected models: [mps.cli.lanuse.library_top.library_top]"
}

def "based on a deleted model file"() {
Expand All @@ -84,6 +89,7 @@ class ConeOfInfluenceComputerTest extends TestBase {
then:
result.output.contains "Some models moved or deleted. Computing cone of influence based on modules."
result.output.contains twoExpectedSolutions()
result.output.contains "all affected models: []"
}

def "based on a modified solution file"() {
Expand All @@ -98,5 +104,6 @@ class ConeOfInfluenceComputerTest extends TestBase {
then:
result.output.contains "Some solutions moved or deleted. Skipping cone of influence."
result.output.contains twoExpectedSolutions()
result.output.contains "all affected models: []"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package org.mps_cli.cone_of_influence

import groovy.transform.Immutable
import org.mps_cli.model.SModel
import org.mps_cli.model.SModuleBase
import org.mps_cli.model.SRepository

import javax.annotation.Nullable

class ConeOfInfluenceComputer {

SRepository repository

Tuple2<List<SModuleBase>, List<SModuleBase>> computeConeOfInfluence(
@Immutable
class Result {
@Nullable List<SModel> affectedModels
List<SModuleBase> affectedModules
List<SModuleBase> affectedModulesAndUpstreamDependencies

List getAt(int idx) {
switch (idx) {
case 0: return affectedModels
case 1: return affectedModules
case 2: return affectedModulesAndUpstreamDependencies
default: throw new RuntimeException("Result has 3 fields")
}
}
}

Result computeConeOfInfluence(
String rootLocation,
List<String> allModifiedFiles
) {
Expand All @@ -24,19 +44,26 @@ class ConeOfInfluenceComputer {

if (modifiedEntities.foundMissingModules) {
println("Some solutions moved or deleted. Skipping cone of influence.")
def modulesUniverse = module2AllUpstreamDependencies.keySet()
[modulesUniverse.toList(), modulesUniverse.toList()]
def modulesUniverse = module2AllUpstreamDependencies.keySet().toList()

new Result(affectedModules: modulesUniverse, affectedModulesAndUpstreamDependencies: modulesUniverse)
} else if (modifiedEntities.foundMissingModels) {
println("Some models moved or deleted. Computing cone of influence based on modules.")
computeGeneric(modifiedEntities.modules, module2AllUpstreamDependencies, module2AllDownstreamDependencies)
def (modules, modulesAndUpstreamDependencies) = (
computeGeneric(modifiedEntities.modules, module2AllUpstreamDependencies, module2AllDownstreamDependencies))

new Result(affectedModules: modules, affectedModulesAndUpstreamDependencies: modulesAndUpstreamDependencies)
} else {
println("Computing cone of influence based on models.")
def (models2AllUpstreamDependencies, models2AllDownstreamDependencies) = EntityDependenciesBuilder.buildModelDependencies(repository)

def (models, modelsAndUpstreamDependencies) =
computeGeneric(modifiedEntities.models, models2AllUpstreamDependencies, models2AllDownstreamDependencies)
def (models, modelsAndUpstreamDependencies) = (
computeGeneric(modifiedEntities.models, models2AllUpstreamDependencies, models2AllDownstreamDependencies))

[models.myModule.unique(), modelsAndUpstreamDependencies.myModule.unique()]
new Result(
affectedModels: models,
affectedModules: models.myModule.unique(),
affectedModulesAndUpstreamDependencies: modelsAndUpstreamDependencies.myModule.unique())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Filesystem2SSolutionBridge {
boolean foundMissingModels = false
Set<SModel> models = []

private boolean registerModulePath(Path path) {
private void registerModulePath(Path path) {
if (Files.notExists(path)) {
foundMissingModules = true
} else {
Expand All @@ -40,7 +40,7 @@ class Filesystem2SSolutionBridge {
}
}

private boolean registerModelPath(Path path) {
private void registerModelPath(Path path) {
if (Files.notExists(path)) {
foundMissingModels = true
} else {
Expand All @@ -55,7 +55,7 @@ class Filesystem2SSolutionBridge {
}
}

private boolean registerPath(Path path) {
private void registerPath(Path path) {
def filename = path.getFileName().toString()

if (filename.matches(modulePattern)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.mps_cli.cone_of_influence.ConeOfInfluenceComputer
import org.mps_cli.cone_of_influence.GitFacade
import org.mps_cli.model.SModel
import org.mps_cli.model.SModuleBase
import org.mps_cli.model.builder.BuildingDepthEnum
import org.mps_cli.model.builder.SModulesRepositoryBuilder
Expand All @@ -28,6 +29,9 @@ class ConeOfInfluenceComputerTask extends DefaultTask {
@Input
List<String> modifiedFiles

@Internal
List<SModel> affectedModels

@Internal
List<SModuleBase> affectedSolutions

Expand All @@ -54,7 +58,7 @@ class ConeOfInfluenceComputerTask extends DefaultTask {
def repository = builder.buildAll(sourcesDir)
def coiComputer = new ConeOfInfluenceComputer(repository: repository)

(affectedSolutions, affectedSolutionsAndUpstreamDependencies) =
(affectedModels, affectedSolutions, affectedSolutionsAndUpstreamDependencies) =
coiComputer.computeConeOfInfluence(gitRepoRootLocation, allModifiedFiles)
}
}
9 changes: 5 additions & 4 deletions mps-cli-py/src/mpscli/model/SModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self, name, uuid, is_do_not_generate):
self.root_nodes = []
self.path_to_model_file = ""
self.is_do_not_generate = is_do_not_generate
self.uuid_2_nodes = {}

def get_nodes(self):
res = []
Expand All @@ -17,7 +18,7 @@ def get_nodes(self):
return res

def get_node_by_uuid(self, uuid):
for n in self.get_nodes():
if n.uuid == uuid:
return n
return None
if len(self.uuid_2_nodes) == 0:
for n in self.get_nodes():
self.uuid_2_nodes[n.uuid] = n
return self.uuid_2_nodes[uuid]
5 changes: 3 additions & 2 deletions mps-cli-py/src/mpscli/model/SNode.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

class SNode:

def __init__(self, uuid, concept, role_in_parent):
def __init__(self, uuid, concept, role_in_parent, parent):
self.uuid = uuid
self.concept = concept
self.role_in_parent = role_in_parent
self.properties = {}
self.references = {}
self.children = []
self.parent = parent

def get_property(self, name):
return self.properties[name]
return self.properties.get(name)

def get_reference(self, name):
return self.references[name]
Expand Down
11 changes: 6 additions & 5 deletions mps-cli-py/src/mpscli/model/SRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SRepository:
def __init__(self):
self.solutions = []
self.languages = []
self.uuid_2_model = {}

def find_solution_by_name(self, name):
for sol in self.solutions:
Expand Down Expand Up @@ -52,8 +53,8 @@ def get_nodes_of_concept(self, concept_name):
return res

def get_model_by_uuid(self, uuid):
for sol in self.solutions:
for m in sol.models:
if m.uuid == uuid:
return m
return None
if len(self.uuid_2_model) == 0:
for sol in self.solutions:
for m in sol.models:
self.uuid_2_model[m.uuid] = m
return self.uuid_2_model.get(uuid)
24 changes: 24 additions & 0 deletions mps-cli-py/src/mpscli/model/builder/NodeIdEncodingUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

class NodeIdEncodingUtils:

def __init__(self):
self.myIndexChars = "0123456789abcdefghijklmnopqrstuvwxyz$_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.MIN_CHAR = ord('$')
self.myCharToValue = {}
for i in range(0, len(self.myIndexChars)):
charValue = ord(self.myIndexChars[i])
self.myCharToValue[charValue - self.MIN_CHAR] = i

# transforms the node id string saved in MPS files and converts it to the proper node id as long
def decode_string(self, uid_string):
res = 0
c = uid_string[0]
value = self.myCharToValue[ord(c) - self.MIN_CHAR]
res = value
for idx in range(1, len(uid_string)):
res = res << 6
c = uid_string[idx]
value = self.myIndexChars.index(c)
res = res | value
return res

6 changes: 3 additions & 3 deletions mps-cli-py/src/mpscli/model/builder/SModelBuilderBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def __init__(self):
self.index_2_reference_role = {}
self.index_2_imported_model_uuid = {}

def extract_node(self, my_model, node_xml):
def extract_node(self, my_model, node_xml, parent):
root_node_id = node_xml.get("id")
root_node_concept = self.index_2_concept[node_xml.get("concept")]
child_role_index = node_xml.get("role")
if child_role_index is None:
child_role = None
else:
child_role = self.index_2_child_role_in_parent[child_role_index]
s_node = SNode(root_node_id, root_node_concept, child_role)
s_node = SNode(root_node_id, root_node_concept, child_role, parent)
for property_xml_node in node_xml.findall("property"):
property_role = property_xml_node.get("role")
property_value = property_xml_node.get("value")
Expand All @@ -40,7 +40,7 @@ def extract_node(self, my_model, node_xml):
ref_name = self.index_2_reference_role[ref_role]
s_node.references[ref_name] = s_node_ref
for child_node_xml in node_xml.findall("node"):
child_node = self.extract_node(my_model, child_node_xml)
child_node = self.extract_node(my_model, child_node_xml, s_node)
s_node.children.append(child_node)

return s_node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def build(self, path):
self.extract_imports_and_registry(model_xml_node)

for node_xml_node in model_xml_node.findall("node"):
root_node = self.extract_node(model, node_xml_node)
root_node = self.extract_node(model, node_xml_node, None)
model.root_nodes.append(root_node)

return model
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def extract_root_node(self, model, mpsr_file):
model_xml_node = tree.getroot()
self.extract_imports_and_registry(model_xml_node)
root_node = model_xml_node.find("node")
return self.extract_node(model, root_node)
return self.extract_node(model, root_node, None)



16 changes: 16 additions & 0 deletions mps-cli-py/tests/test_node_id_encoding_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from mpscli.model.builder.NodeIdEncodingUtils import NodeIdEncodingUtils


class TestStringUtils(unittest.TestCase):

def test_string_utils(self):
"""
Test the StringUtils
"""
su = NodeIdEncodingUtils()
self.assertEqual(5731700211660045982, su.decode_string('4Yb5JA31NUu'))

if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions mps-cli-py/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_build_root_nodes(self, test_data_location, library_top_authors_top_mode
self.assertEqual('4Yb5JA31NUu', root_node.uuid)
self.assertEqual("mps.cli.landefs.people.structure.PersonsContainer", root_node.concept.name)
self.assertEqual("_010_classical_authors", root_node.properties["name"])
self.assertEqual(None, root_node.parent)

@parameterized.expand([('mps_cli_lanuse_file_per_root',
'mps.cli.lanuse.library_top.library_top'),
Expand All @@ -48,6 +49,7 @@ def test_build_nodes(self, test_data_location, library_top_library_top_model_nam
self.assertEqual("Tom Sawyer", tom_sawyer.get_property("name"))
author_of_tom_sawyer = tom_sawyer.get_children("authors")[0].get_reference("person").resolve(self.repo)
self.assertEqual("Mark Twain", author_of_tom_sawyer.get_property("name"))
self.assertEqual(root_node, tom_sawyer.parent)

def get_name(node):
return node.get_property("name")
Expand Down
16 changes: 16 additions & 0 deletions mps-cli-py/tests/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from mpscli.model.builder.NodeIdEncodingUtils import NodeIdEncodingUtils


class TestStringUtils(unittest.TestCase):

def test_string_utils(self):
"""
Test the StringUtils
"""
su = NodeIdEncodingUtils()
self.assertEqual(5731700211660045982, su.decode_string('4Yb5JA31NUu'))

if __name__ == '__main__':
unittest.main()

0 comments on commit 1c89276

Please sign in to comment.