-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework and publish Gradle connector plugin
The connector plugin version is read from the gradle.properties file and added dynamically into all relevant places.
- Loading branch information
Showing
27 changed files
with
184 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dga/dependencymodel/ConfigurationModel.kt → .../dga/connectormodel/ConfigurationModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
interface ConfigurationModel { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...dependencymodel/ConfigurationModelData.kt → .../connectormodel/ConfigurationModelData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
import java.io.Serializable | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../addere/dga/dependencymodel/Dependency.kt → ...h/addere/dga/connectormodel/Dependency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ere/dga/dependencymodel/DependencyImpl.kt → ...dere/dga/connectormodel/DependencyImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
import java.io.Serializable | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...re/dga/dependencymodel/DependencyModel.kt → ...ere/dga/connectormodel/DependencyModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
interface DependencyModel { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ga/dependencymodel/DependencyModelImpl.kt → ...dga/connectormodel/DependencyModelImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
import java.io.Serializable | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...dere/dga/dependencymodel/ProjectModule.kt → ...ddere/dga/connectormodel/ProjectModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../dga/dependencymodel/ProjectModuleImpl.kt → ...e/dga/connectormodel/ProjectModuleImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ch.addere.dga.dependencymodel | ||
package ch.addere.dga.connectormodel | ||
|
||
import java.io.Serializable | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MavenPublication>("maven") { | ||
from(components["kotlin"]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks.withType<PublishToMavenLocal> { | ||
dependsOn(tasks.getByPath(":connector-model:publishToMavenLocal")) | ||
} |
68 changes: 68 additions & 0 deletions
68
connector-plugin/src/main/kotlin/ch/addere/dga/connectorplugin/ConnectorPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Project> { | ||
|
||
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<ProjectModule> | ||
): Map<String, List<ConfigurationModel>> = project.allprojects | ||
.associate { it.name to extractConfiguration(it.configurations, modules) } | ||
|
||
private fun extractConfiguration( | ||
configurationContainer: ConfigurationContainer, | ||
modules: Set<ProjectModule> | ||
): List<ConfigurationModel> = configurationContainer | ||
.flatMap { configurationToDependencies(it, modules) } | ||
.toList() | ||
|
||
private fun configurationToDependencies( | ||
configuration: Configuration, | ||
modules: Set<ProjectModule> | ||
): List<ConfigurationModel> = | ||
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<ProjectModule>, | ||
dependency: Dependency | ||
): Boolean = | ||
modules.map { it.projectModule }.contains(dependency.name) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/DgaModelBuilder.kt
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
...ndency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ModuleDependencyExtractor.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectExtactor.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
dependency-plugin/src/main/kotlin/ch/addere/dga/dependencyplugin/ProjectModuleExtractor.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.