Skip to content

Commit 175e2f9

Browse files
authored
Merge pull request #90 from jakzal/sequential-export
Run export tasks sequentially for more predictability
2 parents 87667a1 + 72afe69 commit 175e2f9

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/ExportFunctionalTest.kt

+36
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,40 @@ class ExportFunctionalTest : FunctionalTest {
4141

4242
assertTrue(File("${projectDir.absolutePath}/structurizr-SystemContext.puml").exists())
4343
}
44+
45+
@Test
46+
fun `it exports multiple workspaces`(@TempDir projectDir: File, @TempDir workspaceDir1: File, @TempDir workspaceDir2: File) {
47+
givenWorkspace(workspaceDir1, "workspace1.dsl")
48+
givenWorkspace(workspaceDir2, "workspace2.dsl")
49+
givenConfiguration(projectDir, """
50+
plugins {
51+
id 'pl.zalas.structurizr-cli'
52+
}
53+
structurizrCli {
54+
export {
55+
format = "plantuml"
56+
workspace = "${workspaceDir1.absolutePath}/workspace1.dsl"
57+
}
58+
export {
59+
format = "plantuml"
60+
workspace = "${workspaceDir2.absolutePath}/workspace2.dsl"
61+
}
62+
export {
63+
format = "json"
64+
workspace = "${workspaceDir1.absolutePath}/workspace1.dsl"
65+
}
66+
export {
67+
format = "json"
68+
workspace = "${workspaceDir2.absolutePath}/workspace2.dsl"
69+
}
70+
}
71+
""")
72+
73+
execute(projectDir, "structurizrCliExport")
74+
75+
assertTrue(File("${workspaceDir1.absolutePath}/structurizr-SystemContext.puml").exists())
76+
assertTrue(File("${workspaceDir2.absolutePath}/structurizr-SystemContext.puml").exists())
77+
assertTrue(File("${workspaceDir1.absolutePath}/workspace1.json").exists())
78+
assertTrue(File("${workspaceDir2.absolutePath}/workspace2.json").exists())
79+
}
4480
}

src/main/kotlin/pl/zalas/gradle/structurizrcli/StructurizrCliPlugin.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ class StructurizrCliPlugin : Plugin<Project> {
6565
// export tasks need to be created once configuration has been processed
6666
extension.exports.forEachIndexed { index, export ->
6767
export.name = export.name.ifEmpty { export.format.replace("/", "-") + index }
68-
tasks.register("structurizrCliExport-${export.name}", Export::class.java) { task ->
68+
tasks.register(export.taskName(), Export::class.java) { task ->
6969
task.dependsOn("structurizrCliExtract")
7070
task.workspace.set(layout.projectDirectory.file(export.workspace))
7171
task.format.set(export.format)
7272
task.structurizrCliJar.set(extract.flatMap { it.structurizrCliJar })
73-
task.structurizrCliDirectory.set(layout.buildDirectory.dir("structurizr-cli"))
73+
task.structurizrCliDirectory.set(structurizrDirectory(extension))
74+
extension.exports.getOrNull(index-1)?.also { precedingExport ->
75+
task.mustRunAfter(precedingExport.taskName())
76+
}
7477
}
7578
}
7679
}
@@ -97,4 +100,6 @@ class StructurizrCliPlugin : Plugin<Project> {
97100
extension.extract.directory?.let {
98101
layout.projectDirectory.dir(it)
99102
} ?: layout.buildDirectory.dir("structurizr-cli").get()
103+
104+
private fun StructurizrCliPluginExtension.Export.taskName() = "structurizrCliExport-${this.name}"
100105
}

src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Export.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ open class Export : DefaultTask() {
4747
fun export() {
4848
project.javaexec { spec ->
4949
spec.workingDir(project.layout.projectDirectory)
50-
spec.classpath(structurizrCliJar.get(), structurizrCliDirectory.dir("lib/*"))
50+
spec.classpath(structurizrCliDirectory.dir("lib/*"))
5151
spec.mainClass.set("com.structurizr.cli.StructurizrCliApplication")
5252
spec.args("export", "-workspace", workspace.get(), "-format", format.get())
5353
}

0 commit comments

Comments
 (0)