Skip to content

Commit

Permalink
mps-cli-gradle-plugin: Abandon COI when solutions deleted (#13)
Browse files Browse the repository at this point in the history
computeConeOfInfluence: when it detects deleted, moved or renamed solutions gives up computation of cone of influence and returns all existing solutions
  • Loading branch information
kolmar authored Aug 13, 2023
1 parent f30af5b commit edee53f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/mps_cli_build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: MPS-CLI_CI

on: [push, pull_request]
on:
push:
branches:
- 'main'
pull_request:

env:
GITHUB_TOKEN: ${{ secrets.MPSCLI_GITHUB_PKG_REGISTRY }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/mps_cli_py_build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: MPS-CLI-PY_CI

on: [push, pull_request]
on:
push:
branches:
- 'main'
pull_request:

env:
GITHUB_TOKEN: ${{ secrets.MPSCLI_GITHUB_PKG_REGISTRY }}
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 @@ -19,7 +19,7 @@ plugins {

// Project versions
ext.major = '0'
ext.minor = '14'
ext.minor = '15'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This Groovy source file was generated by the Gradle 'init' task.
*/
package org.mps_cli.gradle.plugin

class ConeOfInfluenceComputerTest_02 extends TestBase {

def "cone of influence computer test"() {
given:
settingsFile << ""
buildFile << '''
plugins {
id('com.mbeddr.mps_cli')
}
buildModuleDependencies {
sourcesDir = ['../../../../../../../../../mps_test_projects/mps_cli_lanuse_file_per_root']
}
computeConeOfInfluence {
referenceBranchName = "origin/testing/do_not_delete/cone_of_influence_test_02"
gitRepoRootLocation = '../../../../../../../../../'
}
task printConeOfInfluence {
dependsOn computeConeOfInfluence
doLast {
def affectedSolutions = computeConeOfInfluence.affectedSolutions
println "all affected solutions: ${affectedSolutions.collect { it.name }.sort()}"
}
}
'''

when:
runTask("printConeOfInfluence")

then:
result.output.contains "Solutions [mps.cli.lanuse.library_top2.msd] do not exist on current branch. The cone of influence is the entire set of solutions."
result.output.contains "all affected solutions: [mps.cli.lanuse.library_second, mps.cli.lanuse.library_top]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.mps_cli.model.SModuleBase
import org.mps_cli.model.SSolutionModule
import org.mps_cli.model.builder.SSolutionModuleBuilder

import java.nio.file.Files
import java.nio.file.Path

class ConeOfInfluenceComputer {
Expand All @@ -12,7 +13,20 @@ class ConeOfInfluenceComputer {
Map<SModuleBase, Set<SModuleBase>> module2AllUpstreamDependencies,
Map<SModuleBase, Set<SModuleBase>> module2AllDownstreamDependencies) {

List<Path> differentModulesFiles = Filesystem2SSolutionBridge.computeModulesWhichAreModifiedInCurrentBranch(gitRepoLocation, allModifiedFiles)
def modulesUniverse = module2AllUpstreamDependencies.keySet()

HashSet<Path> differentModulesFiles = Filesystem2SSolutionBridge.computeModulesWhichAreModifiedInCurrentBranch(gitRepoLocation, allModifiedFiles)

println(">>>>>>>>>>>> All different modules files:")
differentModulesFiles.each { println it }
println("<<<<<<<<<<<<")

// if any module is deleted (.msd file not available) then COI is the entire universe
def notExistingSolutions = differentModulesFiles.findAll { Files.notExists(it) }
if (notExistingSolutions) {
println("Solutions ${notExistingSolutions.fileName} do not exist on current branch. The cone of influence is the entire set of solutions.")
return new Tuple2(modulesUniverse.toList(), modulesUniverse.toList())
}

List<String> differentModulesIds = differentModulesFiles.collect {
SSolutionModuleBuilder builder = new SSolutionModuleBuilder()
Expand All @@ -21,7 +35,7 @@ class ConeOfInfluenceComputer {
}

// directly affected modules
def differentModulesFromBranch = module2AllUpstreamDependencies.keySet().findAll {differentModulesIds.contains(it.moduleId) }
def differentModulesFromBranch = modulesUniverse.findAll {differentModulesIds.contains(it.moduleId) }
// indirectly potentially affected modules
def downstreamDependenciesOfDirectlyAffectedModules = differentModulesFromBranch.collectMany {module2AllDownstreamDependencies[it] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import static groovy.io.FileType.FILES

class Filesystem2SSolutionBridge {

static List<Path> computeModulesWhichAreModifiedInCurrentBranch(String gitRepoRootLocation, List<String> allModifiedFiles) {
/** Returns a list of .msd Files representing the modified modules. **/
static HashSet<Path> computeModulesWhichAreModifiedInCurrentBranch(String gitRepoRootLocation, List<String> allModifiedFiles) {
def gitRepoLocation = Paths.get(gitRepoRootLocation).toAbsolutePath().normalize()

List<Path> affectedModulesFiles = []
LinkedHashSet<Path> affectedModulesFiles = []
allModifiedFiles.each {
if (it.endsWith('.msd'))
affectedModulesFiles.add(gitRepoLocation.resolve(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class GitFacade {
def differencesString = standardOutputOfCommand('git', 'diff', '--name-only', mergeBase)
def differences = differencesString.split('\n')

println("Differences:")
println(">>>>>>>>>>>>> Differences:")
differences.each { println(it) }
println ("<<<<<<<<<<<<")

differences
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ConeOfInfluenceComputerTask extends DefaultTask {
def solution2AllUpstreamDependencies = project.buildModuleDependencies.module2AllUpstreamDependencies
def solution2AllDownstreamDependencies = project.buildModuleDependencies.module2AllDownstreamDependencies

def allModifiedFiles = modifiedFiles ?:
def allModifiedFiles = modifiedFiles != null ? modifiedFiles :
GitFacade.computeFilesWhichAreModifiedInCurrentBranch(gitRepoRootLocation, referenceBranchName)

ConeOfInfluenceComputer coiComputer = new ConeOfInfluenceComputer()
Expand Down

0 comments on commit edee53f

Please sign in to comment.