From cabd960a4cd593b4ceb67460d397243e129bf5c8 Mon Sep 17 00:00:00 2001 From: Pascal Knecht Date: Sun, 8 Sep 2024 16:41:48 +0200 Subject: [PATCH] Rework and publish Gradle connector plugin The connector plugin version is read from the gradle.properties file and added dynamically into all relevant places. --- .github/workflows/publishConnectorPlugin.yml | 26 +++++++ README.md | 15 ++-- .../build.gradle.kts | 4 +- .../dga/connectormodel}/ConfigurationModel.kt | 2 +- .../connectormodel}/ConfigurationModelData.kt | 2 +- .../addere/dga/connectormodel}/Dependency.kt | 2 +- .../dga/connectormodel}/DependencyImpl.kt | 2 +- .../dga/connectormodel}/DependencyModel.kt | 2 +- .../connectormodel}/DependencyModelImpl.kt | 2 +- .../dga/connectormodel}/ProjectModule.kt | 2 +- .../dga/connectormodel}/ProjectModuleImpl.kt | 2 +- connector-plugin/build.gradle.kts | 49 +++++++++++++ .../dga/connectorplugin/ConnectorPlugin.kt | 68 +++++++++++++++++++ dependency-plugin/build.gradle.kts | 33 --------- .../dga/dependencyplugin/DgaModelBuilder.kt | 20 ------ .../ModuleDependencyExtractor.kt | 47 ------------- .../dga/dependencyplugin/ProjectExtactor.kt | 6 -- .../ProjectModuleExtractor.kt | 12 ---- .../ToolingApiCustomModelPlugin.kt | 14 ---- gradle.properties | 3 +- importer/build.gradle.kts | 15 +++- .../service/GradleProjectLoaderImpl.kt | 2 +- .../domain/service/GradleConnectorService.kt | 2 +- .../domain/service/ModelImporterService.kt | 2 +- .../GradleConnectorServiceImpl.kt | 2 +- importer/src/main/resources/init.gradle.kts | 4 +- settings.gradle.kts | 16 +---- 27 files changed, 184 insertions(+), 172 deletions(-) create mode 100644 .github/workflows/publishConnectorPlugin.yml rename {dependency-model => connector-model}/build.gradle.kts (82%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/ConfigurationModel.kt (78%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/ConfigurationModelData.kt (85%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/Dependency.kt (78%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/DependencyImpl.kt (83%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/DependencyModel.kt (91%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/DependencyModelImpl.kt (87%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/ProjectModule.kt (80%) rename {dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel => connector-model/src/main/kotlin/ch/addere/dga/connectormodel}/ProjectModuleImpl.kt (88%) create mode 100644 connector-plugin/build.gradle.kts create mode 100644 connector-plugin/src/main/kotlin/ch/addere/dga/connectorplugin/ConnectorPlugin.kt delete mode 100644 dependency-plugin/build.gradle.kts delete mode 100644 dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/DgaModelBuilder.kt delete mode 100644 dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ModuleDependencyExtractor.kt delete mode 100644 dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectExtactor.kt delete mode 100644 dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectModuleExtractor.kt delete mode 100644 dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ToolingApiCustomModelPlugin.kt diff --git a/.github/workflows/publishConnectorPlugin.yml b/.github/workflows/publishConnectorPlugin.yml new file mode 100644 index 0000000..b54fae4 --- /dev/null +++ b/.github/workflows/publishConnectorPlugin.yml @@ -0,0 +1,26 @@ +name: Publish Connector Plugin to Gradle Plugin Platform + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + + - name: Check out project + uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + architecture: x64 + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 + + - name: Build and publish connector plugin + run: ./gradlew publishPlugins diff --git a/README.md b/README.md index e83e965..e32120b 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ individual modules with the help of [Mermaid](https://mermaid.js.org/). graph TD vd2a57d(app) -->|implementation| va74ad8(core) vd2a57d(app) -->|implementation| v1bc49d(importer) - v80f88a(dependency-plugin) -->|implementation| v8ebf3d(dependency-model) + va02543(connector-plugin) -->|implementation| v91bd8e(connector-model) + v1bc49d(importer) -->|implementation| v91bd8e(connector-model) v1bc49d(importer) -->|implementation| va74ad8(core) - v1bc49d(importer) -->|implementation| v8ebf3d(dependency-model) ``` Features: @@ -78,7 +78,7 @@ Download and setup this project: git clone https://github.com/ryru/dependency-graph-analyser.git cd dependency-graph-analyser/ ./gradlew clean install -./gradlew :dependency-plugin:publishToMavenLocal +./gradlew :connector-plugin:publishToMavenLocal ``` 1. Download the GitHub code repository @@ -96,6 +96,7 @@ Get an overview of this project by running `dga .`: Analyse project "dependency-graph-analyser" 5 modules 5 dependency configurations (1 unique dependency configurations) + ``` ### Create a Mermaid Chart @@ -112,9 +113,9 @@ Analyse project "dependency-graph-analyser" graph TD vd2a57d(app) -->|implementation| va74ad8(core) vd2a57d(app) -->|implementation| v1bc49d(importer) - v80f88a(dependency-plugin) -->|implementation| v8ebf3d(dependency-model) + va02543(connector-plugin) -->|implementation| v91bd8e(connector-model) + v1bc49d(importer) -->|implementation| v91bd8e(connector-model) v1bc49d(importer) -->|implementation| va74ad8(core) - v1bc49d(importer) -->|implementation| v8ebf3d(dependency-model) ``` @@ -126,7 +127,7 @@ containing the dependencies originating from the module `app`: ``` ./app/build/install/dga/bin/dga . -o app --mermaid-graph -Analyse project "dependency-graph-analyser" + Analyse project "dependency-graph-analyser" 5 modules 5 dependency configurations (1 unique dependency configurations) @@ -137,7 +138,7 @@ Applying filter on data results in: graph TD vd2a57d(app) -->|implementation| va74ad8(core) vd2a57d(app) -->|implementation| v1bc49d(importer) - + ``` - Use `--transitive` to also include transitive dependencies. diff --git a/dependency-model/build.gradle.kts b/connector-model/build.gradle.kts similarity index 82% rename from dependency-model/build.gradle.kts rename to connector-model/build.gradle.kts index c8ce3a5..6159967 100644 --- a/dependency-model/build.gradle.kts +++ b/connector-model/build.gradle.kts @@ -5,8 +5,8 @@ plugins { description = "Data model of the analysed Gradle project" -group = "ch.addere.dga.plugin" -version = "0.1.0" +group = "ch.addere.dga.connectormodel" +version = property("connectorPluginVersion").toString() publishing { repositories { diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModel.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModel.kt similarity index 78% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModel.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModel.kt index eb6ac35..8d5c741 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModel.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModel.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel interface ConfigurationModel { diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModelData.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModelData.kt similarity index 85% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModelData.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModelData.kt index 09f3dc5..52d4d96 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ConfigurationModelData.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ConfigurationModelData.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel import java.io.Serializable diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/Dependency.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/Dependency.kt similarity index 78% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/Dependency.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/Dependency.kt index 9053706..e76dae6 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/Dependency.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/Dependency.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel /** * Represents a Gradle dependency. diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyImpl.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyImpl.kt similarity index 83% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyImpl.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyImpl.kt index 68491f0..33f0dbd 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyImpl.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyImpl.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel import java.io.Serializable diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModel.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModel.kt similarity index 91% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModel.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModel.kt index e3ec26d..87c3d05 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModel.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModel.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel interface DependencyModel { diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModelImpl.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModelImpl.kt similarity index 87% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModelImpl.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModelImpl.kt index 57a4348..5d59fba 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/DependencyModelImpl.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/DependencyModelImpl.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel import java.io.Serializable diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModule.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModule.kt similarity index 80% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModule.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModule.kt index 3257972..de07ff0 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModule.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModule.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel /** * Represents a Gradle project module. These modules usually have a Gradle build file. diff --git a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModuleImpl.kt b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModuleImpl.kt similarity index 88% rename from dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModuleImpl.kt rename to connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModuleImpl.kt index 3db4467..23c0b52 100644 --- a/dependency-model/src/main/kotlin/ch/addere/dga/dependencymodel/ProjectModuleImpl.kt +++ b/connector-model/src/main/kotlin/ch/addere/dga/connectormodel/ProjectModuleImpl.kt @@ -1,4 +1,4 @@ -package ch.addere.dga.dependencymodel +package ch.addere.dga.connectormodel import java.io.Serializable diff --git a/connector-plugin/build.gradle.kts b/connector-plugin/build.gradle.kts new file mode 100644 index 0000000..5f7c6ea --- /dev/null +++ b/connector-plugin/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + id("ch.addere.dga.kotlin-library-conventions") + `java-gradle-plugin` + `maven-publish` + id("com.gradle.plugin-publish") version "1.2.1" +} + +description = "Gradle plugin that is injected into to be analysed Gradle projects" + +group = "ch.addere.dga.connectorplugin" +version = property("connectorPluginVersion").toString() + +dependencies { + implementation(project(":connector-model")) +} + +gradlePlugin { + website = "https://github.com/ryru/dependency-graph-analyser" + vcsUrl = "https://github.com/ryru/dependency-graph-analyser.git" + plugins { + create("gradleDgaPlugin") { + id = "ch.addere.dga.connectorplugin" + displayName = "DGA Connector Plugin" + description = + "Small helper plugin that is injected into existing Gradle projects to analyse the dependency structure." + tags = listOf("dependencyAnalyser", "gradleBuild", "mermaid") + implementationClass = "ch.addere.dga.connectorplugin.ConnectorPlugin.kt" + } + } +} + +publishing { + repositories { + maven { + name = "pluginRepo" + url = uri(layout.projectDirectory.dir("../build/pluginRepo")) + } + + publications { + create("maven") { + from(components["kotlin"]) + } + } + } +} + +tasks.withType { + dependsOn(tasks.getByPath(":connector-model:publishToMavenLocal")) +} diff --git a/connector-plugin/src/main/kotlin/ch/addere/dga/connectorplugin/ConnectorPlugin.kt b/connector-plugin/src/main/kotlin/ch/addere/dga/connectorplugin/ConnectorPlugin.kt new file mode 100644 index 0000000..2f698a9 --- /dev/null +++ b/connector-plugin/src/main/kotlin/ch/addere/dga/connectorplugin/ConnectorPlugin.kt @@ -0,0 +1,68 @@ +package ch.addere.dga.connectorplugin + +import ch.addere.dga.connectormodel.ConfigurationModel +import ch.addere.dga.connectormodel.ConfigurationModelData +import ch.addere.dga.connectormodel.Dependency +import ch.addere.dga.connectormodel.DependencyImpl +import ch.addere.dga.connectormodel.DependencyModel +import ch.addere.dga.connectormodel.DependencyModelImpl +import ch.addere.dga.connectormodel.ProjectModule +import ch.addere.dga.connectormodel.ProjectModuleImpl +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ConfigurationContainer +import org.gradle.tooling.provider.model.ToolingModelBuilder +import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry +import javax.inject.Inject + +class ConnectorPlugin @Inject constructor(private val registry: ToolingModelBuilderRegistry) : + Plugin { + + override fun apply(target: Project) { + registry.register(DgaModelBuilder) + } + + object DgaModelBuilder : ToolingModelBuilder { + + override fun canBuild(modelName: String): Boolean { + return modelName == DependencyModel::class.java.name + } + + override fun buildAll(modelName: String, project: Project): DependencyModel { + val projectName = project.name + val projectModules = project.subprojects.map { ProjectModuleImpl(it.name) }.toSet() + val moduleDependencies = extractModuleDependencies(project, projectModules) + return DependencyModelImpl(projectName, projectModules, moduleDependencies) + } + + private fun extractModuleDependencies( + project: Project, + modules: Set + ): Map> = project.allprojects + .associate { it.name to extractConfiguration(it.configurations, modules) } + + private fun extractConfiguration( + configurationContainer: ConfigurationContainer, + modules: Set + ): List = configurationContainer + .flatMap { configurationToDependencies(it, modules) } + .toList() + + private fun configurationToDependencies( + configuration: Configuration, + modules: Set + ): List = + configuration.dependencies + .map { DependencyImpl(it.name, it.group, it.version) } + .filter { isDependencyWithinProjectModules(modules, it) } + .map { ConfigurationModelData(configuration.name, it, ProjectModuleImpl(it.name)) } + .toList() + + private fun isDependencyWithinProjectModules( + modules: Set, + dependency: Dependency + ): Boolean = + modules.map { it.projectModule }.contains(dependency.name) + } +} diff --git a/dependency-plugin/build.gradle.kts b/dependency-plugin/build.gradle.kts deleted file mode 100644 index 5966331..0000000 --- a/dependency-plugin/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id("ch.addere.dga.kotlin-library-conventions") - `java-gradle-plugin` - `maven-publish` -} - -description = "Gradle plugin that is injected into to be analysed Gradle projects" - -group = "ch.addere.dga.plugin" -version = "0.1.0" - -dependencies { - implementation(project(":dependency-model")) -} - -publishing { - repositories { - maven { - name = "pluginRepo" - url = uri(layout.projectDirectory.dir("../build/pluginRepo")) - } - - publications { - create("maven") { - from(components["kotlin"]) - } - } - } -} - -tasks.withType { - dependsOn(tasks.getByPath(":dependency-model:publishToMavenLocal")) -} diff --git a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/DgaModelBuilder.kt b/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/DgaModelBuilder.kt deleted file mode 100644 index e96a862..0000000 --- a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/DgaModelBuilder.kt +++ /dev/null @@ -1,20 +0,0 @@ -package ch.addere.dga.dependencyplugin - -import ch.addere.dga.dependencymodel.DependencyModel -import ch.addere.dga.dependencymodel.DependencyModelImpl -import org.gradle.api.Project -import org.gradle.tooling.provider.model.ToolingModelBuilder - -class DgaModelBuilder : ToolingModelBuilder { - - override fun canBuild(modelName: String): Boolean { - return modelName == DependencyModel::class.java.name - } - - override fun buildAll(modelName: String, project: Project): DependencyModel { - val projectName = extractProjectName(project) - val projectModules = extractProjectModules(project) - val moduleDependencies = extractModuleDependencies(project, projectModules) - return DependencyModelImpl(projectName, projectModules, moduleDependencies) - } -} diff --git a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ModuleDependencyExtractor.kt b/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ModuleDependencyExtractor.kt deleted file mode 100644 index 1f0f61c..0000000 --- a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ModuleDependencyExtractor.kt +++ /dev/null @@ -1,47 +0,0 @@ -package ch.addere.dga.dependencyplugin - -import ch.addere.dga.dependencymodel.ConfigurationModel -import ch.addere.dga.dependencymodel.ConfigurationModelData -import ch.addere.dga.dependencymodel.Dependency -import ch.addere.dga.dependencymodel.DependencyImpl -import ch.addere.dga.dependencymodel.ProjectModule -import ch.addere.dga.dependencymodel.ProjectModuleImpl -import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration -import org.gradle.api.artifacts.ConfigurationContainer - -fun extractModuleDependencies( - project: Project, - modules: Set -): Map> { - return project.allprojects - .associate { it.name to extractConfiguration(it.configurations, modules) } -} - -private fun extractConfiguration( - configurationContainer: ConfigurationContainer, - modules: Set -): List { - return configurationContainer - .flatMap { configurationToDependencies(it, modules) } - .toList() -} - -private fun configurationToDependencies( - configuration: Configuration, - modules: Set -): List { - val configName = configuration.name - return configuration.dependencies - .map { DependencyImpl(it.name, it.group, it.version) } - .filter { isDependencyWithinProjectModules(modules, it) } - .map { ConfigurationModelData(configName, it, ProjectModuleImpl(it.name)) } - .toList() -} - -private fun isDependencyWithinProjectModules( - modules: Set, - dependency: Dependency -): Boolean { - return modules.map { it.projectModule }.contains(dependency.name) -} diff --git a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectExtactor.kt b/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectExtactor.kt deleted file mode 100644 index e71d3fd..0000000 --- a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectExtactor.kt +++ /dev/null @@ -1,6 +0,0 @@ -package ch.addere.dga.dependencyplugin - -import org.gradle.api.Project - -fun extractProjectName(project: Project): String = project.name - diff --git a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectModuleExtractor.kt b/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectModuleExtractor.kt deleted file mode 100644 index cf2349c..0000000 --- a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectModuleExtractor.kt +++ /dev/null @@ -1,12 +0,0 @@ -package ch.addere.dga.dependencyplugin - -import ch.addere.dga.dependencymodel.ProjectModule -import ch.addere.dga.dependencymodel.ProjectModuleImpl -import org.gradle.api.Project - - -fun extractProjectModules(project: Project): Set { - return project.subprojects - .map { ProjectModuleImpl(it.name) } - .toSortedSet() -} diff --git a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ToolingApiCustomModelPlugin.kt b/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ToolingApiCustomModelPlugin.kt deleted file mode 100644 index 59e1a15..0000000 --- a/dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ToolingApiCustomModelPlugin.kt +++ /dev/null @@ -1,14 +0,0 @@ -package ch.addere.dga.dependencyplugin - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry -import javax.inject.Inject - -class ToolingApiCustomModelPlugin @Inject constructor(private val registry: ToolingModelBuilderRegistry) : - Plugin { - - override fun apply(target: Project) { - registry.register(DgaModelBuilder()) - } -} diff --git a/gradle.properties b/gradle.properties index 18f452c..b3765fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,5 @@ # This file was generated by the Gradle 'init' task. # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties - org.gradle.parallel=true org.gradle.caching=true - +connectorPluginVersion=0.1.2 diff --git a/importer/build.gradle.kts b/importer/build.gradle.kts index 3402911..e6e1e4f 100644 --- a/importer/build.gradle.kts +++ b/importer/build.gradle.kts @@ -1,11 +1,24 @@ +import org.apache.tools.ant.filters.ReplaceTokens + plugins { id("ch.addere.dga.kotlin-library-conventions") `java-gradle-plugin` } +group = "ch.addere.dga.importer" +version = "0.1.0" + description = "Imports project information of to be analysed Gradle project" dependencies { implementation(project(":core")) - implementation(project(":dependency-model")) + implementation(project(":connector-model")) +} + +val connectorPluginVersion = property("connectorPluginVersion").toString() + +tasks.withType { + filesMatching("init.gradle.kts") { + filter(ReplaceTokens::class, "tokens" to mapOf("version" to connectorPluginVersion)) + } } diff --git a/importer/src/main/kotlin/ch/addere/dga/importer/application/service/GradleProjectLoaderImpl.kt b/importer/src/main/kotlin/ch/addere/dga/importer/application/service/GradleProjectLoaderImpl.kt index 12dcaa9..0bfb263 100644 --- a/importer/src/main/kotlin/ch/addere/dga/importer/application/service/GradleProjectLoaderImpl.kt +++ b/importer/src/main/kotlin/ch/addere/dga/importer/application/service/GradleProjectLoaderImpl.kt @@ -1,6 +1,6 @@ package ch.addere.dga.importer.application.service -import ch.addere.dga.dependencymodel.DependencyModel +import ch.addere.dga.connectormodel.DependencyModel import ch.addere.dga.importer.domain.service.ModelImporterService import ch.addere.dga.importer.infrastructure.GradleConnectorServiceImpl import java.io.File diff --git a/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/GradleConnectorService.kt b/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/GradleConnectorService.kt index af0a35d..2f461b6 100644 --- a/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/GradleConnectorService.kt +++ b/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/GradleConnectorService.kt @@ -1,6 +1,6 @@ package ch.addere.dga.importer.domain.service -import ch.addere.dga.dependencymodel.DependencyModel +import ch.addere.dga.connectormodel.DependencyModel import java.io.File interface GradleConnectorService { diff --git a/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/ModelImporterService.kt b/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/ModelImporterService.kt index 4ca3f4b..3e5a635 100644 --- a/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/ModelImporterService.kt +++ b/importer/src/main/kotlin/ch/addere/dga/importer/domain/service/ModelImporterService.kt @@ -1,11 +1,11 @@ package ch.addere.dga.importer.domain.service +import ch.addere.dga.connectormodel.DependencyModel import ch.addere.dga.core.domain.DependencyRepository import ch.addere.dga.core.domain.model.Configuration import ch.addere.dga.core.domain.model.Dependency import ch.addere.dga.core.domain.model.Module import ch.addere.dga.core.domain.service.ModuleRepository -import ch.addere.dga.dependencymodel.DependencyModel class ModelImporterService( private val moduleRepository: ModuleRepository, diff --git a/importer/src/main/kotlin/ch/addere/dga/importer/infrastructure/GradleConnectorServiceImpl.kt b/importer/src/main/kotlin/ch/addere/dga/importer/infrastructure/GradleConnectorServiceImpl.kt index f39c1cd..301691c 100644 --- a/importer/src/main/kotlin/ch/addere/dga/importer/infrastructure/GradleConnectorServiceImpl.kt +++ b/importer/src/main/kotlin/ch/addere/dga/importer/infrastructure/GradleConnectorServiceImpl.kt @@ -1,6 +1,6 @@ package ch.addere.dga.importer.infrastructure -import ch.addere.dga.dependencymodel.DependencyModel +import ch.addere.dga.connectormodel.DependencyModel import ch.addere.dga.importer.domain.service.GradleConnectorService import org.gradle.tooling.GradleConnector import java.io.File diff --git a/importer/src/main/resources/init.gradle.kts b/importer/src/main/resources/init.gradle.kts index e811e55..2fa149c 100644 --- a/importer/src/main/resources/init.gradle.kts +++ b/importer/src/main/resources/init.gradle.kts @@ -5,10 +5,10 @@ initscript { } dependencies { - classpath("ch.addere.dga.plugin:dependency-plugin:0.1.0") + classpath("ch.addere.dga.connectorplugin:connector-plugin:@version@") } } allprojects { - apply() + apply() } diff --git a/settings.gradle.kts b/settings.gradle.kts index d89ea9e..a2cb711 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,28 +1,16 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/8.1.1/userguide/multi_project_builds.html - * This project uses @Incubating APIs which are subject to change. - */ - pluginManagement { - // Include 'plugins build' to define convention plugins. includeBuild("build-logic") } plugins { - // Apply the foojay-resolver plugin to allow automatic download of JDKs id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0" } rootProject.name = "dependency-graph-analyser" include( "app", - "dependency-model", - "dependency-plugin", + "connector-model", + "connector-plugin", "core", "importer", )