Refactoring: cleanup after merge

This commit is contained in:
Alexey Tsvetkov
2016-09-23 23:14:43 +03:00
parent 139cead7b4
commit 18ffb974c7
9 changed files with 33 additions and 50 deletions
@@ -35,6 +35,11 @@
<artifactId>kotlin-android-extensions</artifactId> <artifactId>kotlin-android-extensions</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-gradle-plugin-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler-embeddable</artifactId> <artifactId>kotlin-compiler-embeddable</artifactId>
@@ -121,7 +121,7 @@ private fun Project.createKotlinAfterJavaTask(
} }
class AnnotationProcessingManager( class AnnotationProcessingManager(
private val task: AbstractCompile, task: AbstractCompile,
private val javaTask: JavaCompile, private val javaTask: JavaCompile,
private val taskQualifier: String, private val taskQualifier: String,
private val aptFiles: Set<File>, private val aptFiles: Set<File>,
@@ -130,7 +130,6 @@ class AnnotationProcessingManager(
private val androidVariant: Any? = null) { private val androidVariant: Any? = null) {
private val project = task.project private val project = task.project
private val random = Random()
val wrappersDirectory = File(aptWorkingDir, "wrappers") val wrappersDirectory = File(aptWorkingDir, "wrappers")
val hackAnnotationDir = File(aptWorkingDir, "java_src") val hackAnnotationDir = File(aptWorkingDir, "java_src")
@@ -49,7 +49,7 @@ abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
val taskDescription: String val taskDescription: String
) { ) {
abstract protected fun doTargetSpecificProcessing() abstract protected fun doTargetSpecificProcessing()
val logger = Logging.getLogger(this.javaClass) protected val logger = Logging.getLogger(this.javaClass)!!
protected val sourceSetName: String = sourceSet.name protected val sourceSetName: String = sourceSet.name
protected val sourceRootDir: String = "src/$sourceSetName/kotlin" protected val sourceRootDir: String = "src/$sourceSetName/kotlin"
@@ -179,7 +179,7 @@ class Kotlin2JsSourceSetProcessor(
compileTaskNameSuffix = "kotlin2Js" compileTaskNameSuffix = "kotlin2Js"
) { ) {
override val defaultKotlinDestinationDir: File override val defaultKotlinDestinationDir: File
get() = File(project.buildDir, "kotlin2js/${sourceSetName}") get() = File(project.buildDir, "kotlin2js/$sourceSetName")
private val clean = project.tasks.findByName("clean") private val clean = project.tasks.findByName("clean")
private val build = project.tasks.findByName("build") private val build = project.tasks.findByName("build")
@@ -32,7 +32,7 @@ abstract class TaskToFriendTaskMapper {
sealed class RegexTaskToFriendTaskMapper( sealed class RegexTaskToFriendTaskMapper(
private val prefix: String, private val prefix: String,
private val suffix: String suffix: String
) : TaskToFriendTaskMapper() { ) : TaskToFriendTaskMapper() {
class Default : RegexTaskToFriendTaskMapper("compile", "TestKotlin") class Default : RegexTaskToFriendTaskMapper("compile", "TestKotlin")
class Android : RegexTaskToFriendTaskMapper("compile", "(Unit|Android)TestKotlin") class Android : RegexTaskToFriendTaskMapper("compile", "(Unit|Android)TestKotlin")
@@ -35,7 +35,7 @@ class AndroidGradleWrapper {
androidSourceSet.getJava().srcDir(kotlinDirSet) androidSourceSet.getJava().srcDir(kotlinDirSet)
} }
static def PatternFilterable getResourceFilter(Object androidSourceSet) { static PatternFilterable getResourceFilter(Object androidSourceSet) {
def resources = androidSourceSet.getResources() def resources = androidSourceSet.getResources()
if (resources != null) { if (resources != null) {
return resources.getFilter() return resources.getFilter()
@@ -44,12 +44,12 @@ class AndroidGradleWrapper {
} }
@NotNull @NotNull
static def String getVariantName(Object variant) { static String getVariantName(Object variant) {
return variant.getBuildType().getName() return variant.getBuildType().getName()
} }
@Nullable @Nullable
static def AbstractCompile getJavaCompile(Object baseVariantData) { static AbstractCompile getJavaCompile(Object baseVariantData) {
if (baseVariantData.getMetaClass().getMetaProperty("javaCompileTask")) { if (baseVariantData.getMetaClass().getMetaProperty("javaCompileTask")) {
return baseVariantData.javaCompileTask return baseVariantData.javaCompileTask
} }
@@ -60,7 +60,7 @@ class AndroidGradleWrapper {
} }
@NotNull @NotNull
static def Set<File> getJavaSrcDirs(Object androidSourceSet) { static Set<File> getJavaSrcDirs(Object androidSourceSet) {
return androidSourceSet.getJava().getSrcDirs() return androidSourceSet.getJava().getSrcDirs()
} }
@@ -69,17 +69,17 @@ class AndroidGradleWrapper {
} }
@NotNull @NotNull
static def List<String> getProductFlavorsNames(ApkVariant variant) { static List<String> getProductFlavorsNames(ApkVariant variant) {
return variant.getProductFlavors().iterator().collect { it.getName() } return variant.getProductFlavors().iterator().collect { it.getName() }
} }
@NotNull @NotNull
static def List<AndroidSourceSet> getProductFlavorsSourceSets(BaseExtension extension) { static List<AndroidSourceSet> getProductFlavorsSourceSets(BaseExtension extension) {
return extension.productFlavors.iterator().collect { extension.sourceSets.findByName(it.name) } return extension.productFlavors.iterator().collect { extension.sourceSets.findByName(it.name) }
} }
@NotNull @NotNull
static def DefaultDomainObjectSet<TestVariant> getTestVariants(BaseExtension extension) { static DefaultDomainObjectSet<TestVariant> getTestVariants(BaseExtension extension) {
if (extension.getMetaClass().getMetaMethod("getTestVariants")) { if (extension.getMetaClass().getMetaMethod("getTestVariants")) {
return extension.getTestVariants() return extension.getTestVariants()
} }
@@ -87,7 +87,7 @@ class AndroidGradleWrapper {
} }
@NotNull @NotNull
static def List<File> getRClassFolder(BaseVariant variant) { static List<File> getRClassFolder(BaseVariant variant) {
def list = new ArrayList<File>() def list = new ArrayList<File>()
if (variant.getMetaClass().getMetaMethod("getProcessResources")) { if (variant.getMetaClass().getMetaMethod("getProcessResources")) {
list.add(variant.getProcessResources().getSourceOutputDir()) list.add(variant.getProcessResources().getSourceOutputDir())
@@ -100,17 +100,17 @@ class AndroidGradleWrapper {
return list return list
} }
static def VariantManager getVariantDataManager(BasePlugin plugin) { static VariantManager getVariantDataManager(BasePlugin plugin) {
return plugin.getVariantManager() return plugin.getVariantManager()
} }
static def List<File> getJavaSources(BaseVariantData variantData) { static List<File> getJavaSources(BaseVariantData variantData) {
def result = new LinkedHashSet<File>() def result = new LinkedHashSet<File>()
// user sources // user sources
List<SourceProvider> providers = variantData.variantConfiguration.getSortedSourceProviders(); List<SourceProvider> providers = variantData.variantConfiguration.getSortedSourceProviders()
for (SourceProvider provider : providers) { for (SourceProvider provider : providers) {
result.addAll((provider as AndroidSourceSet).getJava().getSrcDirs()); result.addAll((provider as AndroidSourceSet).getJava().getSrcDirs())
} }
// generated sources // generated sources
@@ -124,24 +124,24 @@ class AndroidGradleWrapper {
} }
else { else {
if (variantData.scope.getGenerateRClassTask() != null) { if (variantData.scope.getGenerateRClassTask() != null) {
result.add(variantData.scope.getRClassSourceOutputDir()); result.add(variantData.scope.getRClassSourceOutputDir())
} }
if (variantData.scope.getGenerateBuildConfigTask() != null) { if (variantData.scope.getGenerateBuildConfigTask() != null) {
result.add(variantData.scope.getBuildConfigSourceOutputDir()); result.add(variantData.scope.getBuildConfigSourceOutputDir())
} }
if (variantData.scope.getAidlCompileTask() != null) { if (variantData.scope.getAidlCompileTask() != null) {
result.add(variantData.scope.getAidlSourceOutputDir()); result.add(variantData.scope.getAidlSourceOutputDir())
} }
if (variantData.scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) { if (variantData.scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) {
result.add(variantData.scope.getClassOutputForDataBinding()); result.add(variantData.scope.getClassOutputForDataBinding())
} }
if (!variantData.variantConfiguration.getRenderscriptNdkModeEnabled() if (!variantData.variantConfiguration.getRenderscriptNdkModeEnabled()
&& variantData.scope.getRenderscriptCompileTask() != null) { && variantData.scope.getRenderscriptCompileTask() != null) {
result.add(variantData.scope.getRenderscriptSourceOutputDir()); result.add(variantData.scope.getRenderscriptSourceOutputDir())
} }
} }
@@ -157,7 +157,7 @@ class AndroidGradleWrapper {
} }
@NotNull @NotNull
static def Map<File, File> getJarToAarMapping(BaseVariantData variantData) { static Map<File, File> getJarToAarMapping(BaseVariantData variantData) {
def jarToLibraryArtifactMap = new HashMap<File, File>() def jarToLibraryArtifactMap = new HashMap<File, File>()
def libraries = getVariantLibraryDependencies(variantData) def libraries = getVariantLibraryDependencies(variantData)
@@ -185,7 +185,7 @@ class AndroidGradleWrapper {
} }
@Nullable @Nullable
private static def Iterable<LibraryDependency> getVariantLibraryDependencies(BaseVariantData variantData) { private static Iterable<LibraryDependency> getVariantLibraryDependencies(BaseVariantData variantData) {
def variantDependency = variantData.variantDependency def variantDependency = variantData.variantDependency
if (variantDependency instanceof DependencyContainer) { if (variantDependency instanceof DependencyContainer) {
// android tools < 2.2 // android tools < 2.2
@@ -58,7 +58,7 @@ internal class GradleIncrementalCacheImpl(targetDataRoot: File, targetOutputDir:
} }
operator fun get(sourceFile: File): Collection<File> = operator fun get(sourceFile: File): Collection<File> =
storage[sourceFile.absolutePath].orEmpty().map { File(it) } storage[sourceFile.absolutePath].orEmpty().map(::File)
override fun dumpValue(value: Collection<String>) = value.dumpCollection() override fun dumpValue(value: Collection<String>) = value.dumpCollection()
@@ -25,8 +25,6 @@ import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import org.gradle.api.tasks.incremental.InputFileDetails import org.gradle.api.tasks.incremental.InputFileDetails
import org.jetbrains.kotlin.bytecode.AnnotationsRemover import org.jetbrains.kotlin.bytecode.AnnotationsRemover
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
import org.jetbrains.kotlin.incremental.md5
import org.jetbrains.org.objectweb.asm.*
import java.io.* import java.io.*
import java.util.* import java.util.*
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -5,8 +5,6 @@ import org.codehaus.groovy.runtime.MethodClosure
import org.gradle.api.GradleException import org.gradle.api.GradleException
import org.gradle.api.file.SourceDirectorySet import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.logging.Logger import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.tasks.SourceTask import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.compile.AbstractCompile import org.gradle.api.tasks.compile.AbstractCompile
@@ -72,9 +70,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
var javaOutputDir: File? = null var javaOutputDir: File? = null
var moduleName: String = "${project.name}-${this.name}" var moduleName: String = "${project.name}-${this.name}"
private val loggerInstance = Logging.getLogger(this.javaClass)
override fun getLogger() = loggerInstance
override fun compile() { override fun compile() {
assert(false, { "unexpected call to compile()" }) assert(false, { "unexpected call to compile()" })
} }
@@ -143,7 +138,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
private val additionalClasspath = arrayListOf<File>() private val additionalClasspath = arrayListOf<File>()
private val compileClasspath: Iterable<File> private val compileClasspath: Iterable<File>
get() = (classpath + additionalClasspath) get() = (classpath + additionalClasspath)
.filterTo(LinkedHashSet()) { it.exists() } .filterTo(LinkedHashSet(), File::exists)
private val kapt2GeneratedSourcesDir: File private val kapt2GeneratedSourcesDir: File
get() = File(project.buildDir, "generated/source/kapt2") get() = File(project.buildDir, "generated/source/kapt2")
@@ -619,6 +614,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
get() = kotlinOptions.outputFile get() = kotlinOptions.outputFile
init { init {
@Suppress("LeakingThis")
outputs.file(MethodClosure(this, "getOutputFile")) outputs.file(MethodClosure(this, "getOutputFile"))
} }
@@ -656,16 +652,6 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
} }
} }
private fun <T: Any> ExtraPropertiesExtension.getOrNull(id: String): T? {
try {
@Suppress("UNCHECKED_CAST")
return get(id) as? T
}
catch (e: ExtraPropertiesExtension.UnknownPropertyException) {
return null
}
}
class GradleMessageCollector(val logger: Logger, val outputCollector: OutputItemsCollector? = null) : MessageCollector { class GradleMessageCollector(val logger: Logger, val outputCollector: OutputItemsCollector? = null) : MessageCollector {
private var hasErrors = false private var hasErrors = false
@@ -4,12 +4,7 @@ import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.Opcodes.* import org.jetbrains.org.objectweb.asm.Opcodes.*
import java.io.File import java.io.File
/* fun generateKotlinAptAnnotation(outputDirectory: File): File {
This file should be a part of AnnotationProcessingManager in kotlin-gradle-plugin,
but org.jetbrains.org.objectweb.asm can't be used there.
*/
public fun generateKotlinAptAnnotation(outputDirectory: File): File {
val packageName = "__gen" val packageName = "__gen"
val className = "KotlinAptAnnotation" val className = "KotlinAptAnnotation"
val classFqName = "$packageName/$className" val classFqName = "$packageName/$className"
@@ -30,7 +25,7 @@ public fun generateKotlinAptAnnotation(outputDirectory: File): File {
return outputFile return outputFile
} }
public fun generateAnnotationProcessorWrapper( fun generateAnnotationProcessorWrapper(
processorFqName: String, processorFqName: String,
packageName: String, packageName: String,
outputDirectory: File, outputDirectory: File,