Skip to content

Commit

Permalink
SLI-549 Package Omnisharp in the distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jul 2, 2021
1 parent 7cc03f8 commit fb57724
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 61 deletions.
174 changes: 113 additions & 61 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.EnumSet
import com.google.protobuf.gradle.*
import com.jetbrains.plugin.blockmap.core.BlockMap
import de.undercouch.gradle.tasks.download.Download
import groovy.lang.GroovyObject
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import java.util.zip.ZipOutputStream
Expand All @@ -23,6 +24,7 @@ plugins {
id("com.google.protobuf") version "0.8.16"
idea
signing
id("de.undercouch.download") version "4.1.1"
}

buildscript {
Expand All @@ -42,6 +44,7 @@ val protobufVersion: String by project
val typescriptVersion: String by project
val jettyVersion: String by project
val intellijBuildVersion: String by project
val omnisharpVersion: String by project

// The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on CI env (Azure)
// On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
Expand Down Expand Up @@ -184,73 +187,128 @@ dependencies {
"typescript"("typescript:typescript:$typescriptVersion@tgz")
}

fun copyPlugins(destinationDir: File, pluginName: String) {
val tsBundlePath = project.configurations.get("typescript").iterator().next()
copy {
from(tarTree(tsBundlePath))
exclude(
"**/loc/**",
"**/lib/*/diagnosticMessages.generated.json"
)
into(file("$destinationDir/$pluginName"))
tasks {

val downloadOmnisharpLinuxZipFile by registering(Download::class) {
src("https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$omnisharpVersion/omnisharp-linux-x64.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-linux-x64.zip"))
overwrite(false)
}
file("$destinationDir/$pluginName/package").renameTo(file("$destinationDir/$pluginName/typescript"))
copy {
from(project.configurations.get("sqplugins"))
into(file("$destinationDir/$pluginName/plugins"))

val downloadOmnisharpOsxZipFile by registering(Download::class) {
src("https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$omnisharpVersion/omnisharp-osx.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-osx.zip"))
overwrite(false)
}
}

tasks.prepareTestingSandbox {
doLast {
copyPlugins(destinationDir, pluginName)
val downloadOmnisharpWindowsZipFile by registering(Download::class) {
src("https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$omnisharpVersion/omnisharp-win-x64.zip")
dest(File(buildDir, "omnisharp-$omnisharpVersion-win-x64.zip"))
overwrite(false)
}
}

tasks.prepareSandbox {
doLast {
copyPlugins(destinationDir, pluginName)
fun copyTypeScript(destinationDir: File, pluginName: String) {
val tsBundlePath = project.configurations.get("typescript").iterator().next()
copy {
from(tarTree(tsBundlePath))
exclude(
"**/loc/**",
"**/lib/*/diagnosticMessages.generated.json"
)
into(file("$destinationDir/$pluginName"))
}
file("$destinationDir/$pluginName/package").renameTo(file("$destinationDir/$pluginName/typescript"))
}
}

val buildPluginBlockmap by tasks.registering {
inputs.file(tasks.buildPlugin.get().archiveFile)
doLast {
val distribZip = tasks.buildPlugin.get().archiveFile.get().asFile
val blockMapBytes = com.fasterxml.jackson.databind.ObjectMapper().writeValueAsBytes(BlockMap(distribZip.inputStream()))
val blockMapFile = File(distribZip.parentFile, "blockmap.json")
blockMapFile.writeBytes(blockMapBytes)
val blockMapFileZipFile = file(distribZip.absolutePath + ".blockmap.zip")
val blockMapFileZip = ZipOutputStream(BufferedOutputStream(FileOutputStream(blockMapFileZipFile)))
val fi = FileInputStream(blockMapFile)
val origin = BufferedInputStream(fi)
val entry = ZipEntry(blockMapFile.name)
blockMapFileZip.putNextEntry(entry)
origin.copyTo(blockMapFileZip, 1024)
origin.close()
blockMapFileZip.close()
artifacts.add("archives", blockMapFileZipFile) {
name = project.name
extension = "zip.blockmap.zip"
type = "zip"
builtBy("buildPluginBlockmap")
fun copyPlugins(destinationDir: File, pluginName: String) {
copy {
from(project.configurations.get("sqplugins"))
into(file("$destinationDir/$pluginName/plugins"))
}
val fileHash = com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(com.jetbrains.plugin.blockmap.core.FileHash(distribZip.inputStream()))
val fileHashJsonFile = file(distribZip.absolutePath + ".hash.json")
fileHashJsonFile.writeText(fileHash)
artifacts.add("archives", fileHashJsonFile) {
name = project.name
extension = "zip.hash.json"
type = "json"
builtBy("buildPluginBlockmap")
}

fun copyOmnisharp(destinationDir: File, pluginName: String) {
copy {
from(zipTree(downloadOmnisharpLinuxZipFile.get().dest))
into(file("$destinationDir/$pluginName/omnisharp/linux"))
}
copy {
from(zipTree(downloadOmnisharpOsxZipFile.get().dest))
into(file("$destinationDir/$pluginName/omnisharp/osx"))
}
copy {
from(zipTree(downloadOmnisharpWindowsZipFile.get().dest))
into(file("$destinationDir/$pluginName/omnisharp/win"))
}
}

prepareSandbox {
dependsOn(downloadOmnisharpLinuxZipFile, downloadOmnisharpOsxZipFile, downloadOmnisharpWindowsZipFile)
doLast {
copyPlugins(destinationDir, pluginName)
copyTypeScript(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
}
}
}

tasks.buildPlugin {
finalizedBy(buildPluginBlockmap)
prepareTestingSandbox {
dependsOn(downloadOmnisharpLinuxZipFile, downloadOmnisharpOsxZipFile, downloadOmnisharpWindowsZipFile)
doLast {
copyPlugins(destinationDir, pluginName)
copyTypeScript(destinationDir, pluginName)
copyOmnisharp(destinationDir, pluginName)
}
}

val buildPluginBlockmap by registering {
inputs.file(buildPlugin.get().archiveFile)
doLast {
val distribZip = buildPlugin.get().archiveFile.get().asFile
val blockMapBytes =
com.fasterxml.jackson.databind.ObjectMapper().writeValueAsBytes(BlockMap(distribZip.inputStream()))
val blockMapFile = File(distribZip.parentFile, "blockmap.json")
blockMapFile.writeBytes(blockMapBytes)
val blockMapFileZipFile = file(distribZip.absolutePath + ".blockmap.zip")
val blockMapFileZip = ZipOutputStream(BufferedOutputStream(FileOutputStream(blockMapFileZipFile)))
val fi = FileInputStream(blockMapFile)
val origin = BufferedInputStream(fi)
val entry = ZipEntry(blockMapFile.name)
blockMapFileZip.putNextEntry(entry)
origin.copyTo(blockMapFileZip, 1024)
origin.close()
blockMapFileZip.close()
artifacts.add("archives", blockMapFileZipFile) {
name = project.name
extension = "zip.blockmap.zip"
type = "zip"
builtBy("buildPluginBlockmap")
}
val fileHash = com.fasterxml.jackson.databind.ObjectMapper()
.writeValueAsString(com.jetbrains.plugin.blockmap.core.FileHash(distribZip.inputStream()))
val fileHashJsonFile = file(distribZip.absolutePath + ".hash.json")
fileHashJsonFile.writeText(fileHash)
artifacts.add("archives", fileHashJsonFile) {
name = project.name
extension = "zip.hash.json"
type = "json"
builtBy("buildPluginBlockmap")
}
}
}

buildPlugin {
finalizedBy(buildPluginBlockmap)
}

jacocoTestReport {
classDirectories.setFrom(files("build/classes/java/main-instrumented"))
reports {
xml.setEnabled(true)
}
}
}


sonarqube {
properties {
property("sonar.projectName", "SonarLint for IntelliJ IDEA")
Expand All @@ -267,13 +325,6 @@ license {
strictCheck = true
}

tasks.jacocoTestReport {
classDirectories.setFrom(files("build/classes/java/main-instrumented"))
reports {
xml.setEnabled(true)
}
}

artifactory {
clientConfig.info.setBuildName("sonarlint-intellij")
clientConfig.info.setBuildNumber(System.getenv("BUILD_BUILDID"))
Expand Down Expand Up @@ -315,3 +366,4 @@ signing {
}



1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ clionBuildVersion=CL-2020.1.3
protobufVersion=3.13.0
typescriptVersion=3.7.5
jettyVersion=9.4.35.v20201120
omnisharpVersion=v1.37.10

0 comments on commit fb57724

Please sign in to comment.