@@ -7,12 +7,15 @@ import de.undercouch.gradle.tasks.download.Download
77import org.gradle.api.DefaultTask
88import org.gradle.api.file.ConfigurableFileCollection
99import org.gradle.api.file.DirectoryProperty
10+ import org.gradle.api.file.RegularFileProperty
11+ import org.gradle.api.tasks.InputFile
1012import org.gradle.api.tasks.InputFiles
1113import org.gradle.api.tasks.OutputDirectory
1214import org.gradle.api.tasks.TaskAction
1315import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
14- import software.aws.toolkits.gradle.ExtractFlareTask
1516import software.aws.toolkits.gradle.changelog.tasks.GeneratePluginChangeLog
17+ import java.net.URI
18+ import java.net.URL
1619
1720plugins {
1821 id(" toolkit-publishing-conventions" )
@@ -93,32 +96,77 @@ data class FlareContent(
9396 val url : String ,
9497)
9598
96- val downloadFlareArtifacts by tasks.registering(Download ::class ) {
97- dependsOn(downloadFlareManifest)
98- inputs.files(downloadFlareManifest)
99-
100- val manifestFile = downloadFlareManifest.map { it.outputFiles.first() }
101- val manifest = manifestFile.map { jacksonObjectMapper().disable(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES ).readValue(it.readText(), FlareManifest ::class .java) }
102-
103- // use darwin-aarch64 because its the smallest and we're going to throw away everything platform specific
104- val latest = manifest.map { it.versions.first() }
105- val latestVersion = latest.map { it.serverVersion }
106- val licensesUrl = latest.map { it.thirdPartyLicenses }
107- val darwin = latest.map { it.targets.first { target -> target.platform == " darwin" && target.arch == " arm64" } }
108- val contentUrls = darwin.map { it.contents.map { content -> content.url } }
99+ abstract class DownloadFlareArtifactsTask : DefaultTask () {
100+ @get:InputFile
101+ abstract val manifestFile: RegularFileProperty
102+
103+ @get:OutputDirectory
104+ abstract val outputDir: DirectoryProperty
105+
106+ @TaskAction
107+ fun download () {
108+ val manifest = jacksonObjectMapper()
109+ .disable(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
110+ .readValue(manifestFile.get().asFile.readText(), FlareManifest ::class .java)
111+
112+ val latest = manifest.versions.first()
113+ val darwin = latest.targets.first { it.platform == " darwin" && it.arch == " arm64" }
114+ val urls = darwin.contents.map { it.url } + latest.thirdPartyLicenses
115+
116+ val destDir = outputDir.get().asFile
117+ destDir.mkdirs()
118+
119+ urls.forEach { url ->
120+ val uri = URI (url)
121+ val fileName = uri.path.substringAfterLast(' /' )
122+ val destFile = destDir.resolve(fileName)
123+ if (! destFile.exists()) {
124+ logger.info(" Downloading $url to $destFile " )
125+ uri.toURL().openStream().use { input ->
126+ destFile.outputStream().use { output ->
127+ input.copyTo(output)
128+ }
129+ }
130+ }
131+ }
132+ }
133+ }
109134
110- val destination = layout.buildDirectory.dir(latestVersion.map { " flare/$it " })
111- outputs.dir(destination)
135+ val downloadFlareArtifacts by tasks.registering(DownloadFlareArtifactsTask ::class ) {
136+ dependsOn(downloadFlareManifest)
137+ manifestFile.set(layout.buildDirectory.file(" flare/manifest.json" ))
138+ outputDir.set(layout.buildDirectory.dir(" flare/artifacts" ))
139+ }
112140
113- src(contentUrls.zip(licensesUrl) { left, right -> left + right})
114- dest(destination)
115- onlyIfModified(true )
116- useETag(true )
141+ abstract class ExtractFlareTask : DefaultTask () {
142+ @get:InputFiles
143+ abstract val zipFiles: ConfigurableFileCollection
144+
145+ @get:OutputDirectory
146+ abstract val outputDir: DirectoryProperty
147+
148+ @TaskAction
149+ fun extract () {
150+ val destDir = outputDir.get().asFile
151+ destDir.deleteRecursively()
152+ destDir.mkdirs()
153+
154+ zipFiles.filter { it.name.endsWith(" .zip" ) }.forEach { zipFile ->
155+ logger.info(" Extracting flare from ${zipFile} " )
156+ project.copy {
157+ from(project.zipTree(zipFile)) {
158+ include(" *.js" )
159+ include(" *.txt" )
160+ }
161+ into(destDir)
162+ }
163+ }
164+ }
117165}
118166
119167val prepareBundledFlare by tasks.registering(ExtractFlareTask ::class ) {
120168 dependsOn(downloadFlareArtifacts)
121- zipFiles.from(downloadFlareArtifacts.map { it.outputFiles })
169+ zipFiles.from(downloadFlareArtifacts.map { it.outputDir.asFileTree })
122170 outputDir.set(layout.buildDirectory.dir(" tmp/extractFlare" ))
123171}
124172
0 commit comments