Skip to content

Commit

Permalink
Merge pull request #90 from jakzal/sequential-export
Browse files Browse the repository at this point in the history
Run export tasks sequentially for more predictability
  • Loading branch information
jakzal authored Apr 26, 2023
2 parents 87667a1 + 72afe69 commit 175e2f9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,40 @@ class ExportFunctionalTest : FunctionalTest {

assertTrue(File("${projectDir.absolutePath}/structurizr-SystemContext.puml").exists())
}

@Test
fun `it exports multiple workspaces`(@TempDir projectDir: File, @TempDir workspaceDir1: File, @TempDir workspaceDir2: File) {
givenWorkspace(workspaceDir1, "workspace1.dsl")
givenWorkspace(workspaceDir2, "workspace2.dsl")
givenConfiguration(projectDir, """
plugins {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
export {
format = "plantuml"
workspace = "${workspaceDir1.absolutePath}/workspace1.dsl"
}
export {
format = "plantuml"
workspace = "${workspaceDir2.absolutePath}/workspace2.dsl"
}
export {
format = "json"
workspace = "${workspaceDir1.absolutePath}/workspace1.dsl"
}
export {
format = "json"
workspace = "${workspaceDir2.absolutePath}/workspace2.dsl"
}
}
""")

execute(projectDir, "structurizrCliExport")

assertTrue(File("${workspaceDir1.absolutePath}/structurizr-SystemContext.puml").exists())
assertTrue(File("${workspaceDir2.absolutePath}/structurizr-SystemContext.puml").exists())
assertTrue(File("${workspaceDir1.absolutePath}/workspace1.json").exists())
assertTrue(File("${workspaceDir2.absolutePath}/workspace2.json").exists())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ class StructurizrCliPlugin : Plugin<Project> {
// export tasks need to be created once configuration has been processed
extension.exports.forEachIndexed { index, export ->
export.name = export.name.ifEmpty { export.format.replace("/", "-") + index }
tasks.register("structurizrCliExport-${export.name}", Export::class.java) { task ->
tasks.register(export.taskName(), Export::class.java) { task ->
task.dependsOn("structurizrCliExtract")
task.workspace.set(layout.projectDirectory.file(export.workspace))
task.format.set(export.format)
task.structurizrCliJar.set(extract.flatMap { it.structurizrCliJar })
task.structurizrCliDirectory.set(layout.buildDirectory.dir("structurizr-cli"))
task.structurizrCliDirectory.set(structurizrDirectory(extension))
extension.exports.getOrNull(index-1)?.also { precedingExport ->
task.mustRunAfter(precedingExport.taskName())
}
}
}
}
Expand All @@ -97,4 +100,6 @@ class StructurizrCliPlugin : Plugin<Project> {
extension.extract.directory?.let {
layout.projectDirectory.dir(it)
} ?: layout.buildDirectory.dir("structurizr-cli").get()

private fun StructurizrCliPluginExtension.Export.taskName() = "structurizrCliExport-${this.name}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class Export : DefaultTask() {
fun export() {
project.javaexec { spec ->
spec.workingDir(project.layout.projectDirectory)
spec.classpath(structurizrCliJar.get(), structurizrCliDirectory.dir("lib/*"))
spec.classpath(structurizrCliDirectory.dir("lib/*"))
spec.mainClass.set("com.structurizr.cli.StructurizrCliApplication")
spec.args("export", "-workspace", workspace.get(), "-format", format.get())
}
Expand Down

0 comments on commit 175e2f9

Please sign in to comment.