From 38bee07fd09787ce97bc81535eafc0379501ddb1 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 7 Nov 2017 16:37:12 +0100 Subject: [PATCH] Remove obsolete protobuf-lite building scripts This logic is now present in custom-dependencies/protobuf-lite/build.gradle --- .../infrastructure/build-protobuf-lite.kts | 83 ---------------- libraries/tools/protobuf-lite/build.gradle | 98 ------------------- 2 files changed, 181 deletions(-) delete mode 100644 generators/infrastructure/build-protobuf-lite.kts delete mode 100644 libraries/tools/protobuf-lite/build.gradle diff --git a/generators/infrastructure/build-protobuf-lite.kts b/generators/infrastructure/build-protobuf-lite.kts deleted file mode 100644 index 13761ae4862..00000000000 --- a/generators/infrastructure/build-protobuf-lite.kts +++ /dev/null @@ -1,83 +0,0 @@ -package org.jetbrains.kotlin.infrastructure - -import java.io.BufferedOutputStream -import java.io.File -import java.io.FileOutputStream -import java.util.jar.JarEntry -import java.util.jar.JarFile -import java.util.zip.ZipOutputStream - -/** - * Strip away all unneeded classes from protobuf-java-*.jar to make a LITE version of the protobuf runtime. - * To do this, we load pom.xml from protobuf jar and heuristically extract information about which classes - * are kept in the lite runtime. - * (This could be done with actually parsing the XML, but this solution works just fine at the moment.) - * Then we take the full protobuf.jar and copy its contents to another jar, except those classes - * which are not needed in the lite runtime. - */ - -fun main(args: Array) { - val INCLUDE_START = "**/" - val INCLUDE_END = ".java" - val POM_PATH = "META-INF/maven/com.google.protobuf/protobuf-java/pom.xml" - - if (args.size != 2) { - error("Usage: kotlinc -script build-protobuf-lite.kts ") - } - - val jarFile = File(args[0]) - val outputPath = args[1] - - assert(jarFile.exists()) { "protobuf jar not found at $jarFile" } - - fun loadAllFromJar(file: File): Map> { - val result = hashMapOf>() - JarFile(file).use { jar -> - for (jarEntry in jar.entries()) { - result[jarEntry.name] = Pair(jarEntry, jar.getInputStream(jarEntry).readBytes()) - } - } - return result - } - - val allFiles = loadAllFromJar(jarFile) - - val keepClasses = arrayListOf() - - val pomBytes = allFiles[POM_PATH]?.second ?: error("pom.xml is not found in protobuf jar at $POM_PATH") - val lines = String(pomBytes).lines() - - var liteProfileReached = false - for (lineUntrimmed in lines) { - val line = lineUntrimmed.trim() - - if (liteProfileReached && line == "") { - break - } - else if (line == "lite") { - liteProfileReached = true - continue - } - - if (liteProfileReached && line.startsWith(INCLUDE_START) && line.endsWith(INCLUDE_END)) { - keepClasses.add(line.removeSurrounding(INCLUDE_START, INCLUDE_END)) - } - } - - assert(liteProfileReached && keepClasses.isNotEmpty()) { "Wrong pom.xml or the format has changed, check its contents at $POM_PATH" } - - val outputFile = File(outputPath).apply { delete() } - ZipOutputStream(BufferedOutputStream(FileOutputStream(outputFile))).use { output -> - for ((name, value) in allFiles) { - val className = name.substringAfter("org/jetbrains/kotlin/protobuf/").substringBeforeLast(".class") - if (keepClasses.any { className == it || className.startsWith(it + "$") }) { - val (entry, bytes) = value - output.putNextEntry(entry) - output.write(bytes) - output.closeEntry() - } - } - } -} - -main(args) diff --git a/libraries/tools/protobuf-lite/build.gradle b/libraries/tools/protobuf-lite/build.gradle deleted file mode 100644 index 668558de2ea..00000000000 --- a/libraries/tools/protobuf-lite/build.gradle +++ /dev/null @@ -1,98 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - -buildscript { - repositories { - jcenter() - } - - dependencies { - classpath "com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}" - } -} - -apply plugin: 'base' -apply plugin: 'com.github.johnrengelman.shadow' - -def protobufVersion = "2.6.1" -version = protobufVersion - -def outputJarPath = "${libsDir}/${archivesBaseName}-${protobufVersion}.jar" - - -configurations { - protobuf - protobufSrc -} - - -dependencies { - protobuf "com.google.protobuf:protobuf-java:$protobufVersion" - protobufSrc "com.google.protobuf:protobuf-java:$protobufVersion:sources" -} - -task shadowJar(type: ShadowJar) { - classifier = "shadow" - version = null - - configurations = [project.configurations.protobuf] - relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) { - exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties") - } -} - -createScriptTask(project, "buildLiteJar") { - dependsOn shadowJar - def inputJar = shadowJar.archivePath - inputs.file(inputJar) - outputs.file(outputJarPath) - args += [ - "${rootDir}/../generators/infrastructure/build-protobuf-lite.kts", - inputJar, - outputJarPath - ] -} - -def artifactJar = [file: file(outputJarPath), builtBy: buildLiteJar] - - - - -task sourcesJar(type: Jar) { - inputs.file configurations.protobufSrc - def tmpSrcDir = "${buildDir}/src" - - doFirst { - copy { - from (zipTree(configurations.protobufSrc.singleFile)) - into tmpSrcDir - } - ant.replaceregexp( - match: 'com\\.google\\.protobuf', - replace: 'org.jetbrains.kotlin.protobuf', - flags: 'g' - ) { - fileset(dir: tmpSrcDir) { - include(name: "**/*.java") - } - } - } - - classifier 'sources' - from ("${tmpSrcDir}/com/google/protobuf") { - into 'org/jetbrains/kotlin/protobuf' - } - - doLast { - delete(tmpSrcDir) - } -} - -artifacts { - it."default"(artifactJar) - archives(artifactJar) - archives(sourcesJar) -} - -assemble { - dependsOn configurations.archives -} \ No newline at end of file