@@ -16,7 +16,6 @@ import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.Manifes
16
16
import java.nio.file.Path
17
17
import java.nio.file.Paths
18
18
19
-
20
19
class ManifestFetcher {
21
20
22
21
private val lspManifestUrl = " https://aws-toolkit-language-servers.amazonaws.com/codewhisperer/0/manifest.json"
@@ -30,7 +29,7 @@ class ManifestFetcher {
30
29
/* *
31
30
* Method which will be used to fetch latest manifest.
32
31
* */
33
- fun fetch () : ManifestManager .Manifest ? {
32
+ fun fetch (): ManifestManager .Manifest ? {
34
33
val localManifest = fetchManifestFromLocal()
35
34
if (localManifest != null ) {
36
35
return localManifest
@@ -39,13 +38,12 @@ class ManifestFetcher {
39
38
return remoteManifest
40
39
}
41
40
42
- private fun fetchManifestFromRemote () : ManifestManager .Manifest ? {
43
- val manifest : ManifestManager .Manifest ?
41
+ private fun fetchManifestFromRemote (): ManifestManager .Manifest ? {
42
+ val manifest: ManifestManager .Manifest ?
44
43
try {
45
44
val manifestString = getTextFromUrl(lspManifestUrl)
46
45
manifest = manifestManager.readManifestFile(manifestString) ? : return null
47
- }
48
- catch (e: Exception ) {
46
+ } catch (e: Exception ) {
49
47
logger.error(" error fetching lsp manifest from remote URL ${e.message} " , e)
50
48
return null
51
49
}
@@ -61,23 +59,21 @@ class ManifestFetcher {
61
59
private fun updateManifestCache () {
62
60
try {
63
61
saveFileFromUrl(lspManifestUrl, lspManifestFilePath)
64
- }
65
- catch (e: Exception ) {
62
+ } catch (e: Exception ) {
66
63
logger.error(" error occurred while saving lsp manifest to local cache ${e.message} " , e)
67
64
}
68
65
}
69
66
70
- private fun fetchManifestFromLocal () : ManifestManager .Manifest ? {
71
- var manifest : ManifestManager .Manifest ? = null
67
+ private fun fetchManifestFromLocal (): ManifestManager .Manifest ? {
68
+ var manifest: ManifestManager .Manifest ? = null
72
69
val localETag = getManifestETagFromLocal()
73
70
val remoteETag = getManifestETagFromUrl()
74
71
// If local and remote have same ETag, we can re-use the manifest file from local to fetch artifacts.
75
72
if (localETag != null && remoteETag != null && localETag == remoteETag) {
76
73
try {
77
74
val manifestContent = lspManifestFilePath.readText()
78
75
manifest = manifestManager.readManifestFile(manifestContent) ? : return null
79
- }
80
- catch (e: Exception ) {
76
+ } catch (e: Exception ) {
81
77
logger.error(" error reading lsp manifest file from local ${e.message} " , e)
82
78
return null
83
79
}
@@ -86,21 +82,20 @@ class ManifestFetcher {
86
82
return manifest
87
83
}
88
84
89
- private fun getManifestETagFromLocal () : String? {
90
- if (lspManifestFilePath.exists()) {
85
+ private fun getManifestETagFromLocal (): String? {
86
+ if (lspManifestFilePath.exists()) {
91
87
val messageDigest = DigestUtil .md5()
92
88
DigestUtil .updateContentHash(messageDigest, lspManifestFilePath)
93
89
return StringUtil .toHexString(messageDigest.digest())
94
90
}
95
91
return null
96
92
}
97
93
98
- private fun getManifestETagFromUrl () : String? {
94
+ private fun getManifestETagFromUrl (): String? {
99
95
try {
100
96
val actualETag = getETagFromUrl(lspManifestUrl)
101
97
return actualETag.trim(' "' )
102
- }
103
- catch (e: Exception ) {
98
+ } catch (e: Exception ) {
104
99
logger.error(" error fetching ETag of lsp manifest from url." , e)
105
100
}
106
101
return null
0 commit comments