Skip to content

Commit

Permalink
Extracted common code to build module repository (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmar authored Aug 29, 2023
1 parent 6099e20 commit 7650c9b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.mps_cli.gradle.plugin

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.mps_cli.model.SRepository
import org.mps_cli.model.builder.SLanguageBuilder
import org.mps_cli.model.builder.SModulesRepositoryBuilder

abstract class AbstractDependenciesBuilderTask extends DefaultTask {
Expand All @@ -13,21 +13,19 @@ abstract class AbstractDependenciesBuilderTask extends DefaultTask {
@Input
List<String> sourcesDir;

@Internal
SRepository repository;

abstract List<Object> allEntities();
abstract List<Object> directDependencies(Object entity);

def buildEntityDependencies(Map<?, Set<?>> entity2AllUpstreamDependencies,
Map<?, Set<?>> entity2AllDownstreamDependencies) {
SLanguageBuilder.clear()
sourcesDir.each {
def dir = new File(it).getAbsoluteFile().canonicalPath
println("loading models from directory: " + dir)
builder.build(dir)
}
repository = builder.buildAll(sourcesDir)

for (Object entity : allEntities()) {
Set<Object> dependencies = [].toSet()
collectUpstreamDependencies(builder.repo, entity, dependencies)
collectUpstreamDependencies(repository, entity, dependencies)
entity2AllUpstreamDependencies[entity] = dependencies
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.mps_cli.model.SRepository
import org.mps_cli.model.builder.SLanguageBuilder
import org.mps_cli.model.builder.SModulesRepositoryBuilder

class ModelBuilderTask extends DefaultTask {
Expand All @@ -24,15 +23,8 @@ class ModelBuilderTask extends DefaultTask {
@TaskAction
def buildModel() {
def builder = new SModulesRepositoryBuilder()
SLanguageBuilder.clear()
sourcesDir.each {
def dir = new File(it).getAbsoluteFile().canonicalPath
println("loading models from directory: " + dir)
builder.build(dir)
}
//setProperty("repository", repository)
repository = builder.repo

repository = builder.buildAll(sourcesDir)
println("number of solutions: " + repository.modules.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ModelDependenciesBuilderTask extends AbstractDependenciesBuilderTask {

@Override
List<Object> allEntities() {
builder.repo.allModels()
repository.allModels()
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ModuleDependenciesBuilderTask extends AbstractDependenciesBuilderTask {

@Override
List<Object> allEntities() {
builder.repo.modules
repository.modules
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class SModulesRepositoryBuilder {

def repo = new SRepository()

def buildAll(List<String> sourcesDir) {
SLanguageBuilder.clear()
sourcesDir.each {
def dir = Paths.get(it).toAbsolutePath().normalize().toString()
println("loading models from directory: " + dir)
build(dir)
}
repo
}

def build(String pathString) {
Date start = new Date()

Expand Down

0 comments on commit 7650c9b

Please sign in to comment.