Skip to content

Commit 7c7dae7

Browse files
committed
feat(amazonq): add license info for the Q lsp server in the log
1 parent ffe192f commit 7c7dae7

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH,
8181
.sortedByDescending { (_, semVer) -> semVer }
8282
}
8383

84-
fun getExistingLspArtifacts(versions: List<Version>, target: VersionTarget?): Boolean {
85-
if (versions.isEmpty() || target?.contents == null) return false
84+
fun getExistingLspArtifacts(targetVersion: Version, target: VersionTarget): Boolean {
85+
if (target.contents == null) return false
8686

87-
val localLSPPath = lspArtifactsPath.resolve(versions.first().serverVersion.toString())
87+
val localLSPPath = lspArtifactsPath.resolve(targetVersion.serverVersion.toString())
8888
if (!localLSPPath.exists()) return false
8989

9090
val hasInvalidFiles = target.contents.any { content ->
@@ -105,9 +105,9 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH,
105105
return !hasInvalidFiles
106106
}
107107

108-
suspend fun tryDownloadLspArtifacts(project: Project, versions: List<Version>, target: VersionTarget?): Path? {
108+
suspend fun tryDownloadLspArtifacts(project: Project, targetVersion: Version, target: VersionTarget): Path? {
109109
val temporaryDownloadPath = Files.createTempDirectory("lsp-dl")
110-
val downloadPath = lspArtifactsPath.resolve(versions.first().serverVersion.toString())
110+
val downloadPath = lspArtifactsPath.resolve(targetVersion.serverVersion.toString())
111111

112112
while (currentAttempt.get() < maxDownloadAttempts) {
113113
currentAttempt.incrementAndGet()
@@ -119,13 +119,19 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH,
119119
AwsCoreBundle.message("amazonqFeatureDev.placeholder.downloading_and_extracting_lsp_artifacts"),
120120
cancellable = true
121121
) {
122-
if (downloadLspArtifacts(temporaryDownloadPath, target) && target != null && !target.contents.isNullOrEmpty()) {
122+
if (downloadLspArtifacts(temporaryDownloadPath, target) && !target.contents.isNullOrEmpty()) {
123123
moveFilesFromSourceToDestination(temporaryDownloadPath, downloadPath)
124124
target.contents
125125
.mapNotNull { it.filename }
126126
.forEach { filename -> extractZipFile(downloadPath.resolve(filename), downloadPath) }
127127
logger.info { "Successfully downloaded and moved LSP artifacts to $downloadPath" }
128128

129+
val thirdPartyLicenses = targetVersion.thirdPartyLicenses
130+
logger.info {
131+
"Installing Amazon Q Language Server v${targetVersion.serverVersion} to: $downloadPath. " +
132+
if (thirdPartyLicenses == null) "" else "Attribution notice can be found at $thirdPartyLicenses"
133+
}
134+
129135
return@withBackgroundProgress downloadPath
130136
}
131137

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ class ArtifactManager @NonInjectable internal constructor(private val manifestFe
7171
throw LspException("Language server versions not found in manifest.", LspException.ErrorCode.NO_COMPATIBLE_LSP_VERSION)
7272
}
7373

74+
val targetVersion = lspVersions.inRangeVersions.first()
75+
7476
// If there is an LSP Manifest with the same version
75-
val target = getTargetFromLspManifest(lspVersions.inRangeVersions)
77+
val target = getTargetFromLspManifest(targetVersion)
7678
// Get Local LSP files and check if we can re-use existing LSP Artifacts
77-
val artifactPath: Path = if (artifactHelper.getExistingLspArtifacts(lspVersions.inRangeVersions, target)) {
79+
val artifactPath: Path = if (artifactHelper.getExistingLspArtifacts(targetVersion, target)) {
7880
artifactHelper.getAllLocalLspArtifactsWithinManifestRange(DEFAULT_VERSION_RANGE).first().first
7981
} else {
80-
artifactHelper.tryDownloadLspArtifacts(project, lspVersions.inRangeVersions, target)
82+
artifactHelper.tryDownloadLspArtifacts(project, targetVersion, target)
8183
?: throw LspException("Failed to download LSP artifacts", LspException.ErrorCode.DOWNLOAD_FAILED)
8284
}
8385
artifactHelper.deleteOlderLspArtifacts(DEFAULT_VERSION_RANGE)
@@ -111,18 +113,18 @@ class ArtifactManager @NonInjectable internal constructor(private val manifestFe
111113
)
112114
}
113115

114-
private fun getTargetFromLspManifest(versions: List<Version>): VersionTarget {
116+
private fun getTargetFromLspManifest(targetVersion: Version): VersionTarget {
115117
val currentOS = getCurrentOS()
116118
val currentArchitecture = getCurrentArchitecture()
117119

118-
val currentTarget = versions.first().targets?.find { target ->
120+
val currentTarget = targetVersion.targets?.find { target ->
119121
target.platform == currentOS && target.arch == currentArchitecture
120122
}
121123
if (currentTarget == null) {
122124
logger.error { "Failed to obtain target for $currentOS and $currentArchitecture" }
123-
throw LspException("Target not found in the current Version: ${versions.first().serverVersion}", LspException.ErrorCode.TARGET_NOT_FOUND)
125+
throw LspException("Target not found in the current Version: ${targetVersion.serverVersion}", LspException.ErrorCode.TARGET_NOT_FOUND)
124126
}
125-
logger.info { "Target found in the current Version: ${versions.first().serverVersion}" }
127+
logger.info { "Target found in the current Version: ${targetVersion.serverVersion}" }
126128
return currentTarget
127129
}
128130
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ManifestFetcher.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ data class Version(
155155
val isDelisted: Boolean? = null,
156156
@JsonProperty("targets")
157157
val targets: List<VersionTarget>? = emptyList(),
158+
@JsonProperty("thirdPartyLicenses")
159+
val thirdPartyLicenses: String? = null,
158160
)
159161

160162
data class Manifest(

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelperTest.kt

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,14 @@ class ArtifactHelperTest {
120120
serverZipPath.parent.toFile().mkdirs()
121121
serverZipPath.toFile().createNewFile()
122122

123-
val versions = listOf(
124-
Version(serverVersion = "1.0.0")
125-
)
123+
val version = Version(serverVersion = "1.0.0")
126124

127125
val target = VersionTarget(contents = contents)
128126

129127
mockkStatic("software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts.LspUtilsKt")
130128
every { generateSHA384Hash(any()) } returns "1234"
131129

132-
val result = artifactHelper.getExistingLspArtifacts(versions, target)
130+
val result = artifactHelper.getExistingLspArtifacts(version, target)
133131

134132
assertThat(result).isTrue()
135133
assertThat(serverZipPath.toFile().exists()).isTrue()
@@ -144,63 +142,55 @@ class ArtifactHelperTest {
144142
serverZipPath.parent.toFile().mkdirs()
145143
serverZipPath.toFile().createNewFile()
146144

147-
val versions = listOf(
148-
Version(serverVersion = "1.0.0")
149-
)
145+
val version = Version(serverVersion = "1.0.0")
150146

151147
val target = VersionTarget(contents = contents)
152148

153149
mockkStatic("software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts.LspUtilsKt")
154150
every { generateSHA384Hash(any()) } returns "1235"
155151

156-
val result = artifactHelper.getExistingLspArtifacts(versions, target)
152+
val result = artifactHelper.getExistingLspArtifacts(version, target)
157153

158154
assertThat(result).isFalse()
159155
assertThat(serverZipPath.toFile().exists()).isFalse()
160156
}
161157

162-
@Test
163-
fun `getExistingLspArtifacts should return false if versions are empty`() {
164-
val versions = emptyList<Version>()
165-
assertThat(artifactHelper.getExistingLspArtifacts(versions, null)).isFalse()
166-
}
167-
168158
@Test
169159
fun `getExistingLspArtifacts should return false if target does not have contents`() {
170-
val versions = listOf(
171-
Version(serverVersion = "1.0.0")
172-
)
173-
assertThat(artifactHelper.getExistingLspArtifacts(versions, null)).isFalse()
160+
val version = Version(serverVersion = "1.0.0")
161+
val target1 = VersionTarget(contents = emptyList())
162+
val target2 = VersionTarget(contents = null)
163+
assertThat(artifactHelper.getExistingLspArtifacts(version, target1)).isFalse()
164+
assertThat(artifactHelper.getExistingLspArtifacts(version, target2)).isFalse()
174165
}
175166

176167
@Test
177168
fun `getExistingLspArtifacts should return false if Lsp path does not exist`() {
178-
val versions = listOf(
179-
Version(serverVersion = "1.0.0")
180-
)
181-
assertThat(artifactHelper.getExistingLspArtifacts(versions, null)).isFalse()
169+
val versions = Version(serverVersion = "1.0.0")
170+
val target = VersionTarget(contents = contents)
171+
assertThat(artifactHelper.getExistingLspArtifacts(versions, target)).isFalse()
182172
}
183173

184174
@Test
185175
fun `tryDownloadLspArtifacts should not download artifacts if target does not have contents`() {
186-
val versions = listOf(Version(serverVersion = "2.0.0"))
187-
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, versions, null) }).isEqualTo(null)
176+
val versions = Version(serverVersion = "2.0.0")
177+
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, versions, VersionTarget()) }).isEqualTo(null)
188178
assertThat(tempDir.resolve("2.0.0").toFile().exists()).isFalse()
189179
}
190180

191181
@Test
192182
fun `tryDownloadLspArtifacts should throw error if failed to download`() {
193-
val versions = listOf(Version(serverVersion = "1.0.0"))
183+
val version = Version(serverVersion = "1.0.0")
194184

195185
val spyArtifactHelper = spyk(artifactHelper)
196186
every { spyArtifactHelper.downloadLspArtifacts(any(), any()) } returns false
197187

198-
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, versions, null) }).isEqualTo(null)
188+
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, version, VersionTarget(contents = contents)) }).isEqualTo(null)
199189
}
200190

201191
@Test
202192
fun `tryDownloadLspArtifacts should throw error after attempts are exhausted`() {
203-
val versions = listOf(Version(serverVersion = "1.0.0"))
193+
val version = Version(serverVersion = "1.0.0")
204194
val target = VersionTarget(contents = contents)
205195
val spyArtifactHelper = spyk(artifactHelper)
206196

@@ -209,7 +199,7 @@ class ArtifactHelperTest {
209199
every { moveFilesFromSourceToDestination(any(), any()) } just Runs
210200
every { extractZipFile(any(), any()) } just Runs
211201

212-
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, versions, target) }).isEqualTo(null)
202+
assertThat(runBlocking { artifactHelper.tryDownloadLspArtifacts(mockProject, version, target) }).isEqualTo(null)
213203
}
214204

215205
@Test

0 commit comments

Comments
 (0)