|
1 | 1 | // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType |
| 4 | +import com.fasterxml.jackson.databind.DeserializationFeature |
| 5 | +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper |
| 6 | +import de.undercouch.gradle.tasks.download.Download |
| 7 | +import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask |
5 | 8 | import software.aws.toolkits.gradle.changelog.tasks.GeneratePluginChangeLog |
6 | | -import software.aws.toolkits.gradle.intellij.IdeFlavor |
7 | | -import software.aws.toolkits.gradle.intellij.IdeVersions |
8 | | -import software.aws.toolkits.gradle.intellij.toolkitIntelliJ |
9 | 9 |
|
10 | 10 | plugins { |
11 | 11 | id("toolkit-publishing-conventions") |
12 | 12 | id("toolkit-publish-root-conventions") |
13 | 13 | id("toolkit-jvm-conventions") |
14 | 14 | id("toolkit-testing") |
| 15 | + id("de.undercouch.download") |
| 16 | +} |
| 17 | + |
| 18 | +buildscript { |
| 19 | + dependencies { |
| 20 | + classpath(libs.bundles.jackson) |
| 21 | + } |
15 | 22 | } |
16 | 23 |
|
17 | 24 | val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") { |
@@ -51,3 +58,82 @@ tasks.check { |
51 | 58 | } |
52 | 59 | } |
53 | 60 | } |
| 61 | + |
| 62 | +val downloadFlareManifest by tasks.registering(Download::class) { |
| 63 | + src("https://aws-toolkit-language-servers.amazonaws.com/qAgenticChatServer/0/manifest.json") |
| 64 | + dest(layout.buildDirectory.file("flare/manifest.json")) |
| 65 | + onlyIfModified(true) |
| 66 | + useETag(true) |
| 67 | +} |
| 68 | + |
| 69 | +data class FlareManifest( |
| 70 | + val versions: List<FlareVersion>, |
| 71 | +) |
| 72 | + |
| 73 | +data class FlareVersion( |
| 74 | + val serverVersion: String, |
| 75 | + val thirdPartyLicenses: String, |
| 76 | + val targets: List<FlareTarget>, |
| 77 | +) |
| 78 | + |
| 79 | +data class FlareTarget( |
| 80 | + val platform: String, |
| 81 | + val arch: String, |
| 82 | + val contents: List<FlareContent> |
| 83 | +) |
| 84 | + |
| 85 | +data class FlareContent( |
| 86 | + val url: String, |
| 87 | +) |
| 88 | + |
| 89 | +val downloadFlareArtifacts by tasks.registering(Download::class) { |
| 90 | + dependsOn(downloadFlareManifest) |
| 91 | + inputs.files(downloadFlareManifest) |
| 92 | + |
| 93 | + val manifestFile = downloadFlareManifest.map { it.outputFiles.first() } |
| 94 | + val manifest = manifestFile.map { jacksonObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).readValue(it.readText(), FlareManifest::class.java) } |
| 95 | + |
| 96 | + // use darwin-aarch64 because its the smallest and we're going to throw away everything platform specific |
| 97 | + val latest = manifest.map { it.versions.first() } |
| 98 | + val latestVersion = latest.map { it.serverVersion } |
| 99 | + val licensesUrl = latest.map { it.thirdPartyLicenses } |
| 100 | + val darwin = latest.map { it.targets.first { it.platform == "darwin" && it.arch == "arm64" } } |
| 101 | + val contentUrls = darwin.map { it.contents.map { content -> content.url } } |
| 102 | + |
| 103 | + val destination = layout.buildDirectory.dir(latestVersion.map { "flare/$it" }) |
| 104 | + outputs.dir(destination) |
| 105 | + |
| 106 | + src(contentUrls.zip(licensesUrl) { left, right -> left + right}) |
| 107 | + dest(destination) |
| 108 | + onlyIfModified(true) |
| 109 | + useETag(true) |
| 110 | +} |
| 111 | + |
| 112 | +val prepareBundledFlare by tasks.registering(Copy::class) { |
| 113 | + dependsOn(downloadFlareArtifacts) |
| 114 | + inputs.files(downloadFlareArtifacts) |
| 115 | + |
| 116 | + val dest = layout.buildDirectory.dir("tmp/extractFlare") |
| 117 | + outputs.dir(dest) |
| 118 | + into(dest) |
| 119 | + |
| 120 | + |
| 121 | + from(downloadFlareArtifacts.map { it.outputFiles.filterNot { it.name.endsWith(".zip") } }) |
| 122 | + doLast { |
| 123 | + copy { |
| 124 | + into(dest) |
| 125 | + includeEmptyDirs = false |
| 126 | + downloadFlareArtifacts.get().outputFiles.filter { it.name.endsWith(".zip") }.forEach { |
| 127 | + from(zipTree(it)) { |
| 128 | + include("*.js") |
| 129 | + include("*.txt") |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +tasks.withType<PrepareSandboxTask>().configureEach { |
| 137 | + intoChild(intellijPlatform.projectName.map { "$it/flare" }) |
| 138 | + .from(prepareBundledFlare) |
| 139 | +} |
0 commit comments