Clean unused dependencies, minor refactorings

This commit is contained in:
Ilya Chernikov
2017-08-22 16:23:42 +02:00
parent 27968c8e13
commit 3e46c59187
29 changed files with 90 additions and 397 deletions
+9 -15
View File
@@ -1,16 +1,19 @@
import org.gradle.jvm.tasks.Jar
description = "Kotlin Android Lint"
apply { plugin("java") }
apply { plugin("java-base") }
val projectsToShadow = listOf(
":plugins:lint",
":plugins:uast-kotlin",
":plugins:uast-kotlin-idea")
tasks.withType<Jar> {
setupRuntimeJar("Kotlin Android Lint")
archiveName = "android-lint.jar"
sourceSets {
"main" {}
"test" {}
}
runtimeJar {
projectsToShadow.forEach {
dependsOn("$it:classes")
project(it).let { p ->
@@ -21,13 +24,4 @@ tasks.withType<Jar> {
}
}
sourceSets {
"main" {}
"test" {}
}
val jar: Jar by tasks
ideaPlugin {
from(jar)
}
ideaPlugin()
@@ -30,7 +30,6 @@ val projectsToInclude = listOf(
":kotlin-daemon-client")
dependencies {
val testCompile by configurations
projectsToInclude.forEach {
jarContents(project(it)) { isTransitive = false }
testCompile(project(it))
+4 -9
View File
@@ -33,11 +33,11 @@ val fatJar by configurations.creating
val compilerJar by configurations.creating
val archives by configurations
val compilerBaseName: String by rootProject.extra
val compilerBaseName = name
val outputJar = File(buildDir, "libs", "$compilerBaseName.jar")
val javaHome = System.getProperty("java.home")
val jreHome = System.getProperty("java.home")
val compilerModules: Array<String> by rootProject.extra
@@ -57,8 +57,8 @@ val ideaCoreSdkJars: Array<String> by rootProject.extra
val coreSdkJarsSimple = ideaCoreSdkJars.filterNot { it == "jdom" || it == "log4j" }.toTypedArray()
fun firstFromJavaHomeThatExists(vararg paths: String): File =
paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull()
?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}")
paths.mapNotNull { File(jreHome, it).takeIf { it.exists() } }.firstOrNull()
?: throw GradleException("Cannot find under '$jreHome' neither of: ${paths.joinToString()}")
compilerModules.forEach { evaluationDependsOn(it) }
@@ -73,7 +73,6 @@ dependencies {
compiledModulesSources.forEach {
fatSourcesJarContents(it)
}
// buildVersion()
fatJarContents(project(":core:builtins", configuration = "builtins"))
fatJarContents(ideaSdkCoreDeps(*coreSdkJarsSimple))
@@ -93,10 +92,6 @@ dependencies {
proguardLibraryJars(project(":kotlin-script-runtime", configuration = "mainJar"))
proguardLibraryJars(project(":kotlin-reflect", configuration = "mainJar"))
proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core"))
// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false })
}
val packCompiler by task<ShadowJar> {
+2 -3
View File
@@ -1,10 +1,9 @@
import org.gradle.jvm.tasks.Jar
description = "Kotlin Formatter"
apply { plugin("java") }
tasks.withType<Jar> {
setupRuntimeJar("Kotlin Formatter")
runtimeJar {
archiveName = "kotlin-formatter.jar"
dependsOn(":idea:formatter:classes")
project(":idea:formatter").let { p ->
+2 -3
View File
@@ -1,10 +1,9 @@
import org.gradle.jvm.tasks.Jar
description = "Kotlin IDE Lazy Resolver"
apply { plugin("java") }
tasks.withType<Jar> {
setupRuntimeJar("Kotlin IDE Lazy Resolver")
runtimeJar {
archiveName = "kotlin-ide-common.jar"
dependsOn(":idea:ide-common:classes")
project(":idea:ide-common").let { p ->
+4 -8
View File
@@ -1,6 +1,8 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
description = "Kotlin IDEA plugin"
buildscript {
repositories {
jcenter()
@@ -60,11 +62,7 @@ dependencies {
sideJars(preloadedDeps("markdown", "kotlinx-coroutines-core", "kotlinx-coroutines-jdk8"))
}
val targetJar = File(buildDir, "libs", "kotlin-plugin.jar")
val shadowTask = task<ShadowJar>("shadowJar") {
setupRuntimeJar("Kotlin IDEA plugin")
archiveName = targetJar.canonicalPath
val jar = runtimeJar(task<ShadowJar>("shadowJar")) {
projectsToShadow.forEach {
dependsOn("$it:classes")
project(it).let { p ->
@@ -78,9 +76,7 @@ val shadowTask = task<ShadowJar>("shadowJar") {
}
ideaPlugin {
dependsOn(shadowTask)
from(targetJar)
dependsOn(":kotlin-script-runtime:jar")
from(jar)
from(sideJars)
}
+10 -19
View File
@@ -1,21 +1,13 @@
import org.gradle.jvm.tasks.Jar
import org.gradle.api.internal.HasConvention
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
description = "Kotlin Mock Runtime for Tests"
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":kotlin-stdlib"))
}
jvmTarget = "1.6"
javaHome = rootProject.extra["JDK_16"] as String
val jar: Jar by tasks
jar.apply {
setupRuntimeJar("Kotlin Mock Runtime for Tests")
from(fileTree("${rootProject.extra["distDir"]}/builtins")) { include("kotlin/**") }
archiveName = "kotlin-mock-runtime-for-test.jar"
dependencies {
compile(project(":kotlin-stdlib"))
}
sourceSets {
@@ -38,17 +30,16 @@ sourceSets {
tasks.withType<JavaCompile> {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
// options.fork = true
options.forkOptions.javaHome = file(rootProject.extra["JDK_16"] as String)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.6"
kotlinOptions.jdkHome = rootProject.extra["JDK_16"] as String
val jar = runtimeJar {
from(fileTree("${rootProject.extra["distDir"]}/builtins")) { include("kotlin/**") }
archiveName = "kotlin-mock-runtime-for-test.jar"
}
task<Copy>("dist") {
into(rootProject.extra["distDir"].toString())
from(jar)
into(rootProject.extra["distDir"].toString())
rename("-${Regex.escape(rootProject.extra["build.number"].toString())}", "")
}
-131
View File
@@ -1,131 +0,0 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Project
import org.jetbrains.org.objectweb.asm.*
import org.gradle.jvm.tasks.Jar
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.util.jar.JarFile
import java.util.zip.ZipOutputStream
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
classpath(ideaSdkDeps("asm-all"))
}
}
apply { plugin("com.github.johnrengelman.shadow") }
// Set to false to prevent relocation and metadata stripping on kotlin-reflect.jar and reflection sources. Use to debug reflection
val obfuscateReflect = true
val classesFromProjectsCfg = configurations.create("classes-from-projects")
val otherDepsCfg = configurations.create("other-deps")
val mainCfg = configurations.create("default")
val outputReflectJarFileBase = "$buildDir/libs/kotlin-reflect"
val coreProjectName = ":core"
val reflectionProjectName = ":core:reflection.jvm"
artifacts.add(mainCfg.name, File(outputReflectJarFileBase + ".jar"))
dependencies {
classesFromProjectsCfg.name(projectDepIntransitive(coreProjectName))
classesFromProjectsCfg.name(projectDepIntransitive(":core:util.runtime"))
classesFromProjectsCfg.name(projectDepIntransitive(reflectionProjectName))
otherDepsCfg.name(protobufLite())
otherDepsCfg.name(commonDep("javax.inject"))
buildVersion()
}
val prePackReflectTask = task<ShadowJar>("pre-pack-reflect") {
classifier = if (obfuscateReflect) outputReflectJarFileBase + "_beforeStrip" else outputReflectJarFileBase
configurations = listOf(mainCfg)
setupRuntimeJar("Kotlin Reflect")
dependsOn("$coreProjectName:assemble", "$reflectionProjectName:assemble", protobufLiteTask)
from(project(reflectionProjectName).getCompiledClasses())
from(project(coreProjectName).getCompiledClasses())
from(project(":core:util.runtime").getCompiledClasses())
from(project(coreProjectName).file("descriptor.loader.java/src")) {
include("META-INF/services/**")
}
from(otherDepsCfg.files)
manifest.attributes.put("Class-Path", "kotlin-runtime.jar")
if (obfuscateReflect) {
relocate("org.jetbrains.kotlin", "kotlin.reflect.jvm.internal.impl")
relocate("javax.inject", "kotlin.reflect.jvm.internal.impl.javax.inject")
}
}
val mainTask = task("prepare") {
dependsOn(prePackReflectTask)
val inFile = File(outputReflectJarFileBase + "_beforeStrip.jar")
val outFile = File(outputReflectJarFileBase + ".jar")
inputs.file(inFile)
outputs.file(outFile)
val annotationRegex = "kotlin/Metadata".toRegex()
val classRegex = "kotlin/reflect/jvm/internal/impl/.*".toRegex()
doLast {
println("Stripping annotations from all classes in $inFile")
println("Input file size: ${inFile.length()} bytes")
fun transform(entryName: String, bytes: ByteArray): ByteArray {
if (!entryName.endsWith(".class")) return bytes
if (!classRegex.matches(entryName.removeSuffix(".class"))) return bytes
var changed = false
val classWriter = ClassWriter(0)
val classVisitor = object : ClassVisitor(Opcodes.ASM5, classWriter) {
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
if (annotationRegex.matches(Type.getType(desc).internalName)) {
changed = true
return null
}
return super.visitAnnotation(desc, visible)
}
}
ClassReader(bytes).accept(classVisitor, 0)
if (!changed) return bytes
return classWriter.toByteArray()
}
ZipOutputStream(BufferedOutputStream(FileOutputStream(outFile))).use { outJar ->
val inJar = JarFile(inFile)
try {
for (entry in inJar.entries()) {
if (entry.isDirectory) continue
val inBytes = inJar.getInputStream(entry).readBytes()
val outBytes = transform(entry.name, inBytes)
if (inBytes.size < outBytes.size) {
error("Size increased for ${entry.name}: was ${inBytes.size} bytes, became ${outBytes.size} bytes")
}
entry.compressedSize = -1L
outJar.putNextEntry(entry)
outJar.write(outBytes)
outJar.closeEntry()
}
}
finally {
// Yes, JarFile does not extend Closeable on JDK 6 so we can't use "use" here
inJar.close()
}
}
println("Output written to $outFile")
println("Output file size: ${outFile.length()} bytes")
}
}
defaultTasks(mainTask.name)
-39
View File
@@ -1,39 +0,0 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.File
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
classpath(ideaSdkDeps("asm-all"))
}
}
apply { plugin("com.github.johnrengelman.shadow") }
val mainCfg = configurations.create("default")
val outputRuntimeJarFileBase = "$buildDir/libs/kotlin-runtime"
artifacts.add(mainCfg.name, File(outputRuntimeJarFileBase + ".jar"))
dependencies {
mainCfg.name(projectDepIntransitive(":core:builtins"))
mainCfg.name(projectDepIntransitive(":kotlin-stdlib"))
buildVersion()
}
val mainTask = task<ShadowJar>("prepare") {
classifier = outputRuntimeJarFileBase
configurations = listOf(mainCfg)
dependsOn(":core:builtins:assemble", ":kotlin-stdlib:assemble")
setupRuntimeJar("Kotlin Runtime")
from(mainCfg.files)
}
defaultTasks(mainTask.name)