1
- import de.undercouch.gradle.tasks.download.Download
2
1
import org.jetbrains.intellij.tasks.PrepareSandboxTask
3
2
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4
- import java.net.URI
5
3
import java.security.MessageDigest
6
4
import java.util.zip.ZipFile
7
- import kotlin.io.path.deleteExisting
8
5
9
6
plugins {
10
7
id(" java" )
11
8
alias(libs.plugins.changelog)
12
- alias(libs.plugins.download)
13
9
alias(libs.plugins.gradleJvmWrapper)
14
10
alias(libs.plugins.grammarkit)
15
11
alias(libs.plugins.intellij)
@@ -41,30 +37,46 @@ repositories {
41
37
mavenCentral()
42
38
ivy {
43
39
url = uri(" https://github.com/PowerShell/PSScriptAnalyzer/releases/download/" )
44
- patternLayout {
45
- artifact( " [revision]/[module].[revision].[ext] " )
46
- }
47
- content {
48
- includeGroup( " PSScriptAnalyzer " )
49
- }
50
- metadataSources {
51
- artifact()
52
- }
40
+ patternLayout { artifact( " [revision]/[module].[revision].[ext] " ) }
41
+ content { includeGroup( " PSScriptAnalyzer " ) }
42
+ metadataSources { artifact() }
43
+ }
44
+ ivy {
45
+ url = uri( " https://github.com/PowerShell/PowerShellEditorServices/releases/download/ " )
46
+ patternLayout { artifact( " v[revision]/[module].[ext] " ) }
47
+ content { includeGroup( " PowerShellEditorServices " ) }
48
+ metadataSources { artifact() }
53
49
}
54
50
}
55
51
52
+ val psScriptAnalyzerVersion: String by project
53
+ val psScriptAnalyzerSha256Hash: String by project
56
54
val psScriptAnalyzer: Configuration by configurations.creating
57
55
56
+ val psesVersion: String by project
57
+ val psesSha256Hash: String by project
58
+ val powerShellEditorServices: Configuration by configurations.creating
59
+
58
60
dependencies {
59
61
implementation(libs.bundles.junixsocket)
60
62
61
63
implementation(libs.lsp4j)
62
64
testImplementation(" org.jetbrains.kotlin:kotlin-test-junit" )
63
65
testImplementation(libs.junit)
64
66
65
- libs.psScriptAnalyzer.get().apply {
66
- psScriptAnalyzer(group = this .group!! , name = this .name, version = this .version, ext = " nupkg" )
67
- }
67
+ psScriptAnalyzer(
68
+ group = " PSScriptAnalyzer" ,
69
+ name = " PSScriptAnalyzer" ,
70
+ version = psScriptAnalyzerVersion,
71
+ ext = " nupkg"
72
+ )
73
+
74
+ powerShellEditorServices(
75
+ group = " PowerShellEditorServices" ,
76
+ name = " PowerShellEditorServices" ,
77
+ version = psesVersion,
78
+ ext = " zip"
79
+ )
68
80
}
69
81
70
82
configurations {
@@ -119,68 +131,31 @@ tasks {
119
131
}
120
132
}
121
133
122
- fun getDependencyTask (
123
- dependencyName : String ,
124
- version : String ,
125
- expectedHash : String ,
126
- uri : URI ,
127
- destination : RegularFile ,
128
- customizeZip : Action <CopySpec >
129
- ): TaskProvider <Copy > {
130
- val download by register<Download >(" download$dependencyName " ) {
131
- group = " dependencies"
132
-
133
- inputs.property(" version" , version)
134
- inputs.property(" hash" , expectedHash)
135
-
136
- // NOTE: Do not overwrite: the verification step should delete an incorrect file.
137
- // NOTE: Notably, this property allows us to skip the task completely if no inputs change.
138
- overwrite(false )
139
-
140
- src(uri)
141
- dest(destination)
142
-
143
- doLast {
144
- println (" Calculating hash for $dependencyName " )
145
- val data = destination.asFile.readBytes()
146
- val hash = MessageDigest .getInstance(" SHA-256" ).let { sha256 ->
147
- sha256.update(data)
148
- sha256.digest().joinToString(" " ) { " %02x" .format(it) }
149
- }
150
- println (" Expected hash for $dependencyName = $expectedHash " )
151
- println (" Calculated hash for $dependencyName = $hash " )
152
- if (! hash.equals(expectedHash, ignoreCase = true )) {
153
- destination.asFile.toPath().deleteExisting()
154
- error(" $dependencyName hash check failed.\n " +
155
- " The downloaded file has been deleted.\n " +
156
- " Please try running the task again, or update the expected hash in the gradle.properties file." )
157
- }
158
- }
134
+ fun File.verifyHash (expectedHash : String ) {
135
+ println (" Calculating hash for $name ..." )
136
+ val data = readBytes()
137
+ val hash = MessageDigest .getInstance(" SHA-256" ).let { sha256 ->
138
+ sha256.update(data)
139
+ sha256.digest().joinToString(" " ) { " %02x" .format(it) }
159
140
}
160
-
161
- return register<Copy >(" get$dependencyName " ) {
162
- group = " dependencies"
163
-
164
- val outDir = projectDir.resolve(" language_host/LanguageHost/modules/$dependencyName " )
165
- doFirst {
166
- if (! outDir.deleteRecursively()) error(" Cannot delete \" $outDir \" ." )
167
- }
168
-
169
- dependsOn(download)
170
- from(zipTree(destination)) {
171
- customizeZip(this )
172
- }
173
- into(outDir)
141
+ println (" Expected hash for $name = $expectedHash " )
142
+ println (" Calculated hash for $name = $hash " )
143
+ if (! hash.equals(expectedHash, ignoreCase = true )) {
144
+ error(" $name hash check failed.\n " +
145
+ " Please try re-downloading the dependency, or update the expected hash in the gradle.properties file." )
174
146
}
175
147
}
176
148
177
- val downloads = layout.buildDirectory.get().dir(" download" )
178
-
179
- val psesVersion: String by project
180
- val psesSha256Hash: String by project
149
+ val verifyPsScriptAnalyzer by registering {
150
+ dependsOn(psScriptAnalyzer)
151
+ inputs.property(" hash" , psScriptAnalyzerSha256Hash)
152
+ doFirst {
153
+ psScriptAnalyzer.singleFile.verifyHash(psScriptAnalyzerSha256Hash)
154
+ }
155
+ }
181
156
182
157
fun PrepareSandboxTask.unpackPsScriptAnalyzer (outDir : String ) {
183
- dependsOn(psScriptAnalyzer)
158
+ dependsOn(psScriptAnalyzer, verifyPsScriptAnalyzer )
184
159
185
160
from(zipTree(psScriptAnalyzer.singleFile)) {
186
161
into(" $outDir /PSScriptAnalyzer" )
@@ -193,34 +168,27 @@ tasks {
193
168
}
194
169
}
195
170
196
- val getPowerShellEditorServices = getDependencyTask(
197
- " PowerShellEditorServices" ,
198
- psesVersion,
199
- psesSha256Hash,
200
- URI (
201
- " https://github.com/PowerShell/PowerShellEditorServices/releases/download/" +
202
- " v$psesVersion /PowerShellEditorServices.zip"
203
- ),
204
- downloads.file(" PowerShellEditorServices.zip" )
205
- ) {
206
- include(" PowerShellEditorServices/**" )
207
- eachFile {
208
- relativePath = RelativePath (true , * relativePath.segments.drop(1 ).toTypedArray())
171
+ val verifyPowerShellEditorServices by registering {
172
+ dependsOn(powerShellEditorServices)
173
+ inputs.property(" hash" , psesSha256Hash)
174
+ doFirst {
175
+ powerShellEditorServices.singleFile.verifyHash(psesSha256Hash)
209
176
}
210
177
}
211
178
212
- val getAllDependencies by registering {
213
- dependsOn(getPowerShellEditorServices)
179
+ fun PrepareSandboxTask.unpackPowerShellEditorServices (outDir : String ) {
180
+ dependsOn(powerShellEditorServices, verifyPowerShellEditorServices)
181
+
182
+ from(zipTree(powerShellEditorServices.singleFile)) {
183
+ into(" $outDir /" )
184
+ include(" PowerShellEditorServices/**" )
185
+ }
214
186
}
215
187
216
188
withType<PrepareSandboxTask > {
217
- dependsOn(getAllDependencies)
218
189
val outDir = " ${intellij.pluginName.get()} /lib/LanguageHost/modules"
219
190
unpackPsScriptAnalyzer(outDir)
220
-
221
- from(" ${project.rootDir} /language_host" ) {
222
- into(" ${intellij.pluginName.get()} /lib/" )
223
- }
191
+ unpackPowerShellEditorServices(outDir)
224
192
}
225
193
226
194
val maxUnpackedPluginBytes: String by project
@@ -265,5 +233,4 @@ tasks {
265
233
)
266
234
})
267
235
}
268
-
269
236
}
0 commit comments