Skip to content

Commit 104ff8c

Browse files
committed
(#109) Build: download PSScriptAnalyzer automatically
1 parent 8283146 commit 104ff8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+62
-37616
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/language_host/current/modules/PSScriptAnalyzer
12
/src/main/gen-parser
23
/src/main/gen-lexer
34

.idea/dictionaries/fried.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import de.undercouch.gradle.tasks.download.Download
12
import org.jetbrains.intellij.tasks.PrepareSandboxTask
3+
import java.security.MessageDigest
4+
import kotlin.io.path.deleteExisting
25

36
plugins {
47
id("java")
58
alias(libs.plugins.changelog)
9+
alias(libs.plugins.download)
610
alias(libs.plugins.grammarkit)
711
alias(libs.plugins.intellij)
812
alias(libs.plugins.kotlin)
@@ -94,7 +98,58 @@ tasks {
9498
kotlinOptions.jvmTarget = "17"
9599
}
96100

101+
val downloads = layout.buildDirectory.get().dir("download")
102+
103+
val psScriptAnalyzerVersion: String by project
104+
val psScriptAnalyzerSha256Hash: String by project
105+
106+
val psScriptAnalyzerFileName = "PSScriptAnalyzer.$psScriptAnalyzerVersion.nupkg"
107+
val psScriptAnalyzerOutFile = downloads.file(psScriptAnalyzerFileName)
108+
109+
val downloadPsScriptAnalyzer by register<Download>("downloadPsScriptAnalyzer") {
110+
inputs.property("version", psScriptAnalyzerVersion)
111+
inputs.property("hash", psScriptAnalyzerSha256Hash)
112+
113+
// NOTE: Do not overwrite: the verification step should delete an incorrect file.
114+
// NOTE: Notably, this property allows us to skip the task completely if no inputs change.
115+
overwrite(false)
116+
117+
src("https://github.com/PowerShell/PSScriptAnalyzer/releases/download/" +
118+
"$psScriptAnalyzerVersion/$psScriptAnalyzerFileName")
119+
dest(psScriptAnalyzerOutFile)
120+
121+
doLast {
122+
val data = psScriptAnalyzerOutFile.asFile.readBytes()
123+
val hash = MessageDigest.getInstance("SHA-256").let { sha256 ->
124+
sha256.update(data)
125+
sha256.digest().joinToString("") { "%02x".format(it) }
126+
}
127+
if (!hash.equals(psScriptAnalyzerSha256Hash, ignoreCase = true)) {
128+
psScriptAnalyzerOutFile.asFile.toPath().deleteExisting()
129+
error("PSScriptAnalyzer hash check failed. Expected ${psScriptAnalyzerSha256Hash}, but got $hash\n" +
130+
"Please try running the task again, or update the expected hash in the gradle.properties file.")
131+
}
132+
}
133+
}
134+
135+
val getPsScriptAnalyzer by register<Copy>("getPsScriptAnalyzer") {
136+
val outDir = projectDir.resolve("language_host/current/LanguageHost/modules/PSScriptAnalyzer")
137+
doFirst {
138+
if (!outDir.deleteRecursively()) error("Cannot delete \"$outDir\".")
139+
}
140+
141+
dependsOn(downloadPsScriptAnalyzer)
142+
from(zipTree(psScriptAnalyzerOutFile))
143+
// NuGet stuff:
144+
exclude("_manifest/**", "_rels/**", "package/**", "[Content_Types].xml", "*.nuspec")
145+
146+
// Compatibility profiles, see https://github.com/PowerShell/PSScriptAnalyzer/issues/1148
147+
exclude("compatibility_profiles/**")
148+
into(outDir)
149+
}
150+
97151
withType<PrepareSandboxTask> {
152+
dependsOn(getPsScriptAnalyzer)
98153
from("${project.rootDir}/language_host/current") {
99154
into("${intellij.pluginName.get()}/lib/")
100155
}

gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
kotlin.stdlib.default.dependency = false
1+
kotlin.stdlib.default.dependency=false
2+
3+
psScriptAnalyzerVersion=1.21.0
4+
psScriptAnalyzerSha256Hash=66353f139f4f1ffaa532fdeed965e70afbb8400b4810b6b2b91e091119aa6fad

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ junixsocket = ["junixsocket-common", "junixsocket-native-common"]
1313

1414
[plugins]
1515
changelog = { id = "org.jetbrains.changelog", version = "2.2.0" }
16+
download = { id = "de.undercouch.download", version = "5.6.0" }
1617
grammarkit = { id = "org.jetbrains.grammarkit", version = "2022.3.2.2" }
1718
intellij = { id = "org.jetbrains.intellij", version = "1.17.2" }
1819
kotlin = { id = "org.jetbrains.kotlin.jvm", version = "1.9.23" }
Binary file not shown.

language_host/current/LanguageHost/modules/PSScriptAnalyzer/PSScriptAnalyzer.psd1

Lines changed: 0 additions & 314 deletions
This file was deleted.

language_host/current/LanguageHost/modules/PSScriptAnalyzer/PSScriptAnalyzer.psm1

Lines changed: 0 additions & 282 deletions
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)