Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 89 additions & 4 deletions plugins/amazonq/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import de.undercouch.gradle.tasks.download.Download
import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
import software.aws.toolkits.gradle.changelog.tasks.GeneratePluginChangeLog
import software.aws.toolkits.gradle.intellij.IdeFlavor
import software.aws.toolkits.gradle.intellij.IdeVersions
import software.aws.toolkits.gradle.intellij.toolkitIntelliJ

plugins {
id("toolkit-publishing-conventions")
id("toolkit-publish-root-conventions")
id("toolkit-jvm-conventions")
id("toolkit-testing")
id("de.undercouch.download")
}

buildscript {
dependencies {
classpath(libs.bundles.jackson)
}
}

val changelog = tasks.register<GeneratePluginChangeLog>("pluginChangeLog") {
Expand Down Expand Up @@ -51,3 +58,81 @@ tasks.check {
}
}
}

val downloadFlareManifest by tasks.registering(Download::class) {
src("https://aws-toolkit-language-servers.amazonaws.com/qAgenticChatServer/0/manifest.json")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assign to a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot share this with the plugin code

dest(layout.buildDirectory.file("flare/manifest.json"))
onlyIfModified(true)
useETag(true)
}

data class FlareManifest(
val versions: List<FlareVersion>,
)

data class FlareVersion(
val serverVersion: String,
val thirdPartyLicenses: String,
val targets: List<FlareTarget>,
)

data class FlareTarget(
val platform: String,
val arch: String,
val contents: List<FlareContent>
)

data class FlareContent(
val url: String,
)

val downloadFlareArtifacts by tasks.registering(Download::class) {
dependsOn(downloadFlareManifest)
inputs.files(downloadFlareManifest)

val manifestFile = downloadFlareManifest.map { it.outputFiles.first() }
val manifest = manifestFile.map { jacksonObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).readValue(it.readText(), FlareManifest::class.java) }

// use darwin-aarch64 because its the smallest and we're going to throw away everything platform specific
val latest = manifest.map { it.versions.first() }
val latestVersion = latest.map { it.serverVersion }
val licensesUrl = latest.map { it.thirdPartyLicenses }
val darwin = latest.map { it.targets.first { target -> target.platform == "darwin" && target.arch == "arm64" } }
val contentUrls = darwin.map { it.contents.map { content -> content.url } }

val destination = layout.buildDirectory.dir(latestVersion.map { "flare/$it" })
outputs.dir(destination)

src(contentUrls.zip(licensesUrl) { left, right -> left + right})
dest(destination)
onlyIfModified(true)
useETag(true)
}

val prepareBundledFlare by tasks.registering(Copy::class) {
dependsOn(downloadFlareArtifacts)
inputs.files(downloadFlareArtifacts)

val dest = layout.buildDirectory.dir("tmp/extractFlare")
into(dest)

from(downloadFlareArtifacts.map { it.outputFiles.filterNot { file -> file.name.endsWith(".zip") } })
doLast {
copy {
into(dest)
includeEmptyDirs = false
downloadFlareArtifacts.get().outputFiles.filter { it.name.endsWith(".zip") }.forEach {
dest.get().file(it.parentFile.name).asFile.createNewFile()
from(zipTree(it)) {
include("*.js")
include("*.txt")
}
}
}
}
}

tasks.withType<PrepareSandboxTask>().configureEach {
intoChild(intellijPlatform.projectName.map { "$it/flare" })
.from(prepareBundledFlare)
}
Loading