Skip to content

Commit

Permalink
Update the download url and jar name to the latest release (2024.01.02)
Browse files Browse the repository at this point in the history
* the tag name is no longer the classic v1.2.3, but it's now year.month.day
* the downloaded jar no longer has version in its name
* the legacy versioning scheme is still supported, but structurizr has removed most of their past releases (only v1.34.0 and v1.35.0 were kept)
  • Loading branch information
jakzal committed Jan 8, 2024
1 parent 0b89fe3 commit 4248814
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The `version` property can be used To force a specific release.

```kotlin
structurizrCli {
version = "1.30.0"
version = "2024.01.02"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class DownloadFunctionalTest : FunctionalTest {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.30.0"
version = "2024.01.02"
}
""")

execute(projectDir, "structurizrCliDownload")

assertTrue(File("${projectDir.absolutePath}/build/downloads/structurizr-cli-1.30.0.zip").exists())
assertTrue(File("${projectDir.absolutePath}/build/downloads/structurizr-cli-2024.01.02.zip").exists())
}

@Test
Expand All @@ -46,7 +46,7 @@ class DownloadFunctionalTest : FunctionalTest {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.20.1"
version = "2024.01.02"
download {
directory = "tmp"
}
Expand All @@ -55,7 +55,7 @@ class DownloadFunctionalTest : FunctionalTest {

execute(projectDir, "structurizrCliDownload")

assertTrue(File("${projectDir.absolutePath}/tmp/structurizr-cli-1.20.1.zip").exists())
assertTrue(File("${projectDir.absolutePath}/tmp/structurizr-cli-2024.01.02.zip").exists())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ class ExportFunctionalTest : FunctionalTest {
assertTrue(File("${projectDir.absolutePath}/structurizr-SystemContext.puml").exists())
}

@Test
fun `it exports the workspace with a legacy structurizr cli`(@TempDir projectDir: File) {
givenWorkspace(projectDir, "workspace.dsl")
givenConfiguration(projectDir, """
plugins {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.35.0"
export {
format = "plantuml"
workspace = "${projectDir.absolutePath}/workspace.dsl"
}
}
""")

execute(projectDir, "structurizrCliExport")

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

@Test
fun `it exports the workspace to a specified output dir`(@TempDir projectDir: File) {
givenWorkspace(projectDir, "workspace.dsl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,29 @@ class ExtractFunctionalTest : FunctionalTest {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.30.0"
version = "2024.01.02"
}
""")

execute(projectDir, "structurizrCliExtract")

assertTrue(File("${projectDir.absolutePath}/build/structurizr-cli/lib/structurizr-cli-1.30.0.jar").exists())
assertTrue(File("${projectDir.absolutePath}/build/structurizr-cli/lib/structurizr-cli.jar").exists())
}

@Test
fun `it extracts the downloaded legacy structurizr cli`(@TempDir projectDir: File) {
givenConfiguration(projectDir, """
plugins {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.35.0"
}
""")

execute(projectDir, "structurizrCliExtract")

assertTrue(File("${projectDir.absolutePath}/build/structurizr-cli/lib/structurizr-cli-1.35.0.jar").exists())
}

@Test
Expand All @@ -45,7 +61,7 @@ class ExtractFunctionalTest : FunctionalTest {
id 'pl.zalas.structurizr-cli'
}
structurizrCli {
version = "1.19.0"
version = "2024.01.02"
extract {
directory = "structurizr-cli"
}
Expand All @@ -54,6 +70,6 @@ class ExtractFunctionalTest : FunctionalTest {

execute(projectDir, "structurizrCliExtract")

assertTrue(File("${projectDir.absolutePath}/structurizr-cli/lib/structurizr-cli-1.19.0.jar").exists())
assertTrue(File("${projectDir.absolutePath}/structurizr-cli/lib/structurizr-cli.jar").exists())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class StructurizrCliPlugin : Plugin<Project> {
tasks.register("structurizrCliDownload", Download::class.java) { task ->
task.version.set(version.flatMap { it.version })
task.downloadDirectory.set(downloadsDirectory(extension))
task.downloadUrlTemplate.set("https://github.com/structurizr/cli/releases/download/v{VERSION}/structurizr-cli-{VERSION}.zip")
task.downloadUrlTemplate.set("https://github.com/structurizr/cli/releases/download/{VERSION}/structurizr-cli.zip")
task.legacyDownloadUrlTemplate.set("https://github.com/structurizr/cli/releases/download/v{VERSION}/structurizr-cli-{VERSION}.zip")
}

private fun Project.registerExtractTask(extension: StructurizrCliPluginExtension, version: TaskProvider<Version>, download: TaskProvider<Download>) =
Expand Down
15 changes: 13 additions & 2 deletions src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Download.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ open class Download : DefaultTask() {
@Input
val version: Property<String> = project.objects.property(String::class.java)

// Example: https://github.com/structurizr/cli/releases/download/2024.01.02/structurizr-cli.zip
@Input
val downloadUrlTemplate: Property<String> = project.objects.property(String::class.java)

// Example: https://github.com/structurizr/cli/releases/download/v1.35.0/structurizr-cli-1.35.0.zip
@Input
val downloadUrl: Provider<String> = downloadUrlTemplate.flatMap { t -> version.map { v -> t.replace("{VERSION}", v) } }
val legacyDownloadUrlTemplate: Property<String> = project.objects.property(String::class.java)

@Input
val downloadUrl: Provider<String> = version.flatMap { v ->
when {
v.matches("^[0-9]{4}\\..*".toRegex()) -> downloadUrlTemplate.map { t -> t.replace("{VERSION}", v) }
else -> legacyDownloadUrlTemplate.map { t -> t.replace("{VERSION}", v) }
}
}

@OutputDirectory
val downloadDirectory: DirectoryProperty = project.objects.directoryProperty()

@OutputFile
val downloadDestination: Provider<RegularFile> = version.flatMap { v -> downloadDirectory.file("structurizr-cli-$v.zip") }
val downloadDestination: Provider<RegularFile> =
version.flatMap { v -> downloadDirectory.file("structurizr-cli-$v.zip") }

init {
group = "documentation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ open class Extract : DefaultTask() {
val structurizrCliDirectory: DirectoryProperty = project.objects.directoryProperty()

@OutputFile
val structurizrCliJar: Provider<RegularFile> = version.flatMap { v -> structurizrCliDirectory.file("lib/structurizr-cli-$v.jar") }
val structurizrCliJar: Provider<RegularFile> = version.flatMap { v ->
when {
v.matches("^[0-9]{4}\\..*".toRegex()) -> structurizrCliDirectory.file("lib/structurizr-cli.jar")
else -> structurizrCliDirectory.file("lib/structurizr-cli-$v.jar")
}
}

init {
group = "documentation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ open class Version : DefaultTask() {

private fun latestVersion(): String = URL("https://api.github.com/repos/structurizr/cli/releases/latest")
.readText()
.replace("(?smi).*?\"tag_name\":\\s*\"v([0-9.]*)\".*".toRegex(), "$1")
.replace("(?smi).*?\"tag_name\":\\s*\"v?([0-9.]*)\".*".toRegex(), "$1")
}

0 comments on commit 4248814

Please sign in to comment.