Skip to content

Commit

Permalink
🧱 Allow nightly CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 23, 2024
1 parent 0661dd3 commit bb67688
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
18 changes: 12 additions & 6 deletions plugin/src/main/kotlin/org/jetbrains/qodana/Qodana.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Installer {
val log: Logger = Logger.getLogger(Installer::class.java.name)

companion object {
private const val LATEST_VERSION = "2024.1.8"
private const val LATEST_VERSION = "v2024.1.8"
private const val RELEASE_DOWNLOAD_URL =
"https://github.com/JetBrains/qodana-cli/releases/download/v%s/qodana_%s_%s"
"https://github.com/JetBrains/qodana-cli/releases/download/%s/qodana_%s_%s"

fun getQodanaUrl(
platform: String = getPlatformName(),
Expand Down Expand Up @@ -70,15 +70,21 @@ class Installer {
fun getChecksum(version: String = getLatestVersion()): String {
val platform = getPlatformName()
val arch = getArchName()
return CHECKSUMS[version]?.get("${platform}_${arch}")
return CHECKSUMS[version.removePrefix("v")]?.get("${platform}_${arch}")
?: throw IllegalArgumentException("Unsupported combination of version, platform and architecture: $version ${platform}_${arch}")
}
}

fun setup(path: File, downloadURL: String = getQodanaUrl(), version: String = getLatestVersion()): String {
fun setup(
path: File,
version: String = getLatestVersion(),
): String {
val downloadURL = getQodanaUrl(version = version)
val useNightly = version == "nightly"

if (path.exists()) {
try {
verifyChecksum(path, getChecksum(version))
if (!useNightly) verifyChecksum(path, getChecksum(version))
return path.absolutePath
} catch (e: IOException) {
log.warning("Checksum verification failed. Redownloading the binary.")
Expand All @@ -88,7 +94,7 @@ class Installer {

try {
download(downloadURL, path)
verifyChecksum(path, getChecksum(version))
if (!useNightly) verifyChecksum(path, getChecksum(version))
} catch (e: IOException) {
throw IOException("Unable to download latest qodana binary", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QodanaPlugin : Plugin<Project> {
project.file(extension.qodanaPath)
})
arguments.convention(listOf())
useNightly.convention(false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import java.io.File

@UntrackedTask(because = "Qodana tracks the state") // TODO:
open class QodanaScanTask : Exec() {
private val currentPath = System.getenv("PATH")
private val currentHome = System.getenv("HOME")

/**
* Root directory of the project to be analyzed.
*/
Expand Down Expand Up @@ -64,11 +67,27 @@ open class QodanaScanTask : Exec() {
@Optional
val arguments: ListProperty<String> = objectFactory.listProperty(String::class.java)


/**
* Use a nightly version of Qodana CLI.
*/
@Input
@Optional
val useNightly = objectFactory.property<Boolean>()

@TaskAction
override fun exec() {
setArgs(getArguments())
executable = Installer().setup(qodanaPath.get())

executable = (if (useNightly.get()) "nightly" else Installer.getLatestVersion()).let {
Installer().setup(
qodanaPath.get(),
version = it
)
}
environment(QODANA_ENV, QODANA_ENV_NAME)
environment("PATH", currentPath)
environment("HOME", currentHome)

ByteArrayOutputStream().use { os ->
standardOutput = TeeOutputStream(System.out, os)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QodanaScanTaskTest : BaseTest() {
}

@Test
fun `run qodana in a non-empty directory and fail with threshold`() {
fun `run qodana in a container in a non-empty directory and fail with threshold`() {
val githubActions = "true".equals(System.getenv("GITHUB_ACTIONS"), ignoreCase = true)
val isLinux = System.getProperty("os.name").contains("Linux")
if (githubActions) {
Expand All @@ -60,6 +60,29 @@ class QodanaScanTaskTest : BaseTest() {
assertTrue(e.message!!.contains("The number of problems exceeds"))
}
}
//
// @Test
// fun `run qodana in a non-empty directory and fail a with threshold`() {
// buildFile.groovy("""
// $EXTENSION_NAME {
// }
// $QODANA_SCAN_TASK_NAME {
// environment = [
// "QD_PRODUCT_INTERNAL_FEED" : "https://data.services.jetbrains.com/products",
// "QODANA_LICENSE_ONLY_TOKEN": "",
// ]
// arguments = ["--fail-threshold", "0", "--property=idea.headless.enable.statistics=false"]
// useNightly = true
// }
// """.trimIndent())
// file("main.py").writeText("print('Hello, world!')\n\n\n\n\n\nprintln()")
// file("qodana.yaml").writeText("ide: QDPY-EAP")
// try {
// runTaskForCommand(QODANA_SCAN_TASK_NAME)
// } catch (e: Exception) {
// assertTrue(e.message!!.contains("The number of problems exceeds"))
// }
// }

@Test
fun `task loads from the configuration cache`() {
Expand Down

0 comments on commit bb67688

Please sign in to comment.