diff --git a/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt b/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt index 714425fddd9..030d4b99d56 100644 --- a/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt +++ b/libraries/examples/annotation-processor-example/src/main/kotlin/example/ExampleAnnotationProcessor.kt @@ -11,7 +11,7 @@ import javax.tools.Diagnostic public class ExampleAnnotationProcessor : AbstractProcessor() { private companion object { - val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.getCanonicalName() + val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.canonicalName val SUFFIX_OPTION = "suffix" val GENERATE_KOTLIN_CODE_OPTION = "generate.kotlin.code" val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated" @@ -20,17 +20,17 @@ public class ExampleAnnotationProcessor : AbstractProcessor() { override fun process(annotations: MutableSet?, roundEnv: RoundEnvironment): Boolean { val elements = roundEnv.getElementsAnnotatedWith(ExampleAnnotation::class.java) - val elementUtils = processingEnv.getElementUtils() - val filer = processingEnv.getFiler() + val elementUtils = processingEnv.elementUtils + val filer = processingEnv.filer - val options = processingEnv.getOptions() + val options = processingEnv.options val generatedFileSuffix = options[SUFFIX_OPTION] ?: "Generated" val generateKotlinCode = "true" == options[GENERATE_KOTLIN_CODE_OPTION] val kotlinGenerated = options[KAPT_KOTLIN_GENERATED_OPTION] for (element in elements) { - val packageName = elementUtils.getPackageOf(element).getQualifiedName().toString() - val simpleName = element.getSimpleName() + val packageName = elementUtils.getPackageOf(element).qualifiedName.toString() + val simpleName = element.simpleName val className = simpleName.toString().capitalize() + generatedFileSuffix filer.createSourceFile(className).openWriter().use { with(it) { @@ -38,7 +38,7 @@ public class ExampleAnnotationProcessor : AbstractProcessor() { appendln("public final class $className {}") }} - if (generateKotlinCode && kotlinGenerated != null && element.getKind() == ElementKind.CLASS) { + if (generateKotlinCode && kotlinGenerated != null && element.kind == ElementKind.CLASS) { File(kotlinGenerated, "$simpleName.kt").writer().buffered().use { it.appendln("package $packageName") it.appendln("fun $simpleName.customToString() = \"$simpleName: \" + toString()") diff --git a/libraries/examples/browser-example-with-library/src/test/kotlin/sample/SampleTest.kt b/libraries/examples/browser-example-with-library/src/test/kotlin/sample/SampleTest.kt index 9d86cfa69e4..96784ce14c3 100644 --- a/libraries/examples/browser-example-with-library/src/test/kotlin/sample/SampleTest.kt +++ b/libraries/examples/browser-example-with-library/src/test/kotlin/sample/SampleTest.kt @@ -11,11 +11,11 @@ open class SampleTest { open val driver: WebDriver = HtmlUnitDriver(true) @test fun homePage(): Unit { - driver.get("file://" + File("sample.html").getCanonicalPath()) + driver.get("file://" + File("sample.html").canonicalPath) Thread.sleep(1000) val foo = driver.findElement(By.id("foo"))!! - val text = foo.getText() ?: "" + val text = foo.text ?: "" println("Found $foo with text '$text'") assertEquals("x=30 y=200 z=100 u=1000", text.trim()) } diff --git a/libraries/examples/browser-example/src/test/kotlin/sample/SampleTest.kt b/libraries/examples/browser-example/src/test/kotlin/sample/SampleTest.kt index 97ff7b20da5..9fb131e709d 100644 --- a/libraries/examples/browser-example/src/test/kotlin/sample/SampleTest.kt +++ b/libraries/examples/browser-example/src/test/kotlin/sample/SampleTest.kt @@ -11,11 +11,11 @@ open class SampleTest { open val driver: WebDriver = HtmlUnitDriver(true) @test fun homePage(): Unit { - driver.get("file://" + File("sample.html").getCanonicalPath()) + driver.get("file://" + File("sample.html").canonicalPath) Thread.sleep(1000) val foo = driver.findElement(By.id("foo"))!! - val text = foo.getText() ?: "" + val text = foo.text ?: "" println("Found $foo with text '$text'") assertEquals("Some Dynamically Created Content!!!", text.trim()) } diff --git a/libraries/stdlib/src/kotlin/concurrent/Locks.kt b/libraries/stdlib/src/kotlin/concurrent/Locks.kt index 9d28db85996..4380dbb1110 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Locks.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Locks.kt @@ -42,7 +42,7 @@ public inline fun ReentrantReadWriteLock.read(action: () -> T): T { public inline fun ReentrantReadWriteLock.write(action: () -> T): T { val rl = readLock() - val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0 + val readCount = if (writeHoldCount == 0) readHoldCount else 0 repeat(readCount) { rl.unlock() } val wl = writeLock() diff --git a/libraries/stdlib/src/kotlin/io/files/Utils.kt b/libraries/stdlib/src/kotlin/io/files/Utils.kt index 537eab2bc83..cbfd21ddb9c 100644 --- a/libraries/stdlib/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/src/kotlin/io/files/Utils.kt @@ -50,7 +50,7 @@ public fun createTempFile(prefix: String = "tmp", suffix: String? = null, direct */ @Deprecated("This property has unclear semantics and will be removed soon.") public val File.directory: File - get() = if (isDirectory()) this else parentFile!! + get() = if (isDirectory) this else parentFile!! /** * Returns parent of this abstract path name, or `null` if it has no parent. @@ -265,20 +265,20 @@ public fun File.relativePath(descendant: File): String { public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long { if (!exists()) { throw NoSuchFileException(file = this, reason = "The source file doesn't exist") - } else if (isDirectory()) { + } else if (isDirectory) { throw IllegalArgumentException("Use copyRecursively to copy a directory $this") } else if (dst.exists()) { if (!overwrite) { throw FileAlreadyExistsException(file = this, other = dst, reason = "The destination file already exists") - } else if (dst.isDirectory() && dst.listFiles().any()) { + } else if (dst.isDirectory && dst.listFiles().any()) { // In this case file should be copied *into* this directory, // no matter whether it is empty or not return copyTo(dst.resolve(name), overwrite, bufferSize) } } - dst.getParentFile()?.mkdirs() + dst.parentFile?.mkdirs() dst.delete() val input = FileInputStream(this) return input.use { @@ -340,12 +340,12 @@ public fun File.copyRecursively(dst: File, } else { val relPath = src.relativeTo(this) val dstFile = File(dst, relPath) - if (dstFile.exists() && !(src.isDirectory() && dstFile.isDirectory())) { + if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) { if (onError(dstFile, FileAlreadyExistsException(file = src, other = dstFile, reason = "The destination file already exists")) == OnErrorAction.TERMINATE) return false - } else if (src.isDirectory()) { + } else if (src.isDirectory) { dstFile.mkdirs() } else { if (src.copyTo(dstFile, true) != src.length()) { diff --git a/libraries/stdlib/test/JavaClassTest.kt b/libraries/stdlib/test/JavaClassTest.kt index 0a998352bb7..8bfec0fcdf8 100644 --- a/libraries/stdlib/test/JavaClassTest.kt +++ b/libraries/stdlib/test/JavaClassTest.kt @@ -8,8 +8,8 @@ class C() class JavaClassTest() : TestCase() { fun testMe () { - assertEquals("java.util.ArrayList", java.util.ArrayList().javaClass.getName()) - assertEquals("java.util.ArrayList", ArrayList::class.java.getName()) - assertEquals("testjc.C", C::class.java.getName()) + assertEquals("java.util.ArrayList", java.util.ArrayList().javaClass.name) + assertEquals("java.util.ArrayList", ArrayList::class.java.name) + assertEquals("testjc.C", C::class.java.name) } } \ No newline at end of file diff --git a/libraries/stdlib/test/io/FileTreeWalks.kt b/libraries/stdlib/test/io/FileTreeWalks.kt index b7683e800c1..1c25fd54811 100644 --- a/libraries/stdlib/test/io/FileTreeWalks.kt +++ b/libraries/stdlib/test/io/FileTreeWalks.kt @@ -130,7 +130,7 @@ class FileTreeWalkTest { val basedir = createTestFiles() try { val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8") - assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory() }.map { + assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory }.map { it.relativeToOrSelf(basedir).invariantSeparatorsPath }.toHashSet()) } finally { @@ -145,7 +145,7 @@ class FileTreeWalkTest { val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8") val namesTopDown = HashSet() fun enter(file: File) { - assertTrue(file.isDirectory()) + assertTrue(file.isDirectory) for (child in file.listFiles()) { if (child.name.endsWith("txt")) child.delete() @@ -168,7 +168,7 @@ class FileTreeWalkTest { val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8") val namesTopDown = HashSet() fun enter(file: File) { - assertTrue(file.isDirectory()) + assertTrue(file.isDirectory) for (child in file.listFiles()) { if (child.name.endsWith("txt")) child.delete() @@ -287,7 +287,7 @@ class FileTreeWalkTest { failed.add(dir.name) } basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory). - fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) } + fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) } assertTrue(stack.isEmpty()) for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) { assertTrue(dirs.contains(File(fileName)), fileName) @@ -313,7 +313,7 @@ class FileTreeWalkTest { files.clear() dirs.clear() basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory). - fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) } + fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) } assertTrue(stack.isEmpty()) assertEquals(setOf("1"), failed) assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs) @@ -335,7 +335,7 @@ class FileTreeWalkTest { val visited = HashSet() val block: (File) -> Unit = { assertTrue(!visited.contains(it), it.toString()) - assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString()) + assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString()) visited.add(it) } basedir.walkTopDown().forEach(block) @@ -353,7 +353,7 @@ class FileTreeWalkTest { val visited = HashSet() val block: (File) -> Unit = { assertTrue(!visited.contains(it), it.toString()) - assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString()) + assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString()) visited.add(it) } basedir.walkTopDown().forEach(block) @@ -376,7 +376,7 @@ class FileTreeWalkTest { val basedir1 = createTestFiles() try { basedir1.walkTopDown().forEach { - if (it.isFile()) { + if (it.isFile) { makeBackup(it) } } @@ -389,7 +389,7 @@ class FileTreeWalkTest { val basedir2 = createTestFiles() try { basedir2.walkTopDown().forEach { - if (it.isFile()) { + if (it.isFile) { makeBackup(it) } } @@ -424,7 +424,7 @@ class FileTreeWalkTest { val found = HashSet() for (file in basedir.walkTopDown()) { if (file.name == ".git") { - found.add(file.getParentFile()) + found.add(file.parentFile) } } assertEquals(3, found.size) diff --git a/libraries/stdlib/test/io/Files.kt b/libraries/stdlib/test/io/Files.kt index c83fe5417f7..cac0d013e0f 100644 --- a/libraries/stdlib/test/io/Files.kt +++ b/libraries/stdlib/test/io/Files.kt @@ -20,16 +20,16 @@ class FilesTest { @test fun testCreateTempDir() { val dirSuf = System.currentTimeMillis().toString() val dir1 = createTempDir("temp", dirSuf) - assertTrue(dir1.exists() && dir1.isDirectory() && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf)) + assertTrue(dir1.exists() && dir1.isDirectory && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf)) assertFailsWith(IllegalArgumentException::class) { createTempDir("a") } val dir2 = createTempDir("temp") - assertTrue(dir2.exists() && dir2.isDirectory() && dir2.name.endsWith(".tmp")) + assertTrue(dir2.exists() && dir2.isDirectory && dir2.name.endsWith(".tmp")) val dir3 = createTempDir() - assertTrue(dir3.exists() && dir3.isDirectory()) + assertTrue(dir3.exists() && dir3.isDirectory) dir1.delete() dir2.delete() @@ -63,10 +63,10 @@ class FilesTest { createTempFile("temp3", ".kt", dir) // This line works only with Kotlin File.listFiles(filter) - val result = dir.listFiles { it -> it.getName().endsWith(".kt") } // todo ambiguity on SAM + val result = dir.listFiles { it -> it.name.endsWith(".kt") } // todo ambiguity on SAM assertEquals(2, result!!.size) // This line works both with Kotlin File.listFiles(filter) and the same Java function because of SAM - val result2 = dir.listFiles { it -> it.getName().endsWith(".kt") } + val result2 = dir.listFiles { it -> it.name.endsWith(".kt") } assertEquals(2, result2!!.size) } @@ -410,7 +410,7 @@ class FilesTest { } @test fun copyToNameWithoutParent() { - val currentDir = File("").getAbsoluteFile()!! + val currentDir = File("").absoluteFile!! val srcFile = createTempFile() val dstFile = createTempFile(directory = currentDir) try { @@ -474,7 +474,7 @@ class FilesTest { for (file in src.walkTopDown()) { val dstFile = File(dst, file.relativeTo(src)) assertTrue(dstFile.exists()) - if (dstFile.isFile()) { + if (dstFile.isFile) { assertEquals(file.readText(), dstFile.readText()) } diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt index 577f848112b..f464ef539ae 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper.kt @@ -95,7 +95,7 @@ public abstract class AnnotationProcessorWrapper( return } - val annotationsFilePath = processingEnv.getOptions().get(KAPT_ANNOTATION_OPTION) + val annotationsFilePath = processingEnv.options[KAPT_ANNOTATION_OPTION] val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) { FileKotlinAnnotationProvider(annotationsFile) @@ -108,13 +108,13 @@ public abstract class AnnotationProcessorWrapper( } override fun getSupportedAnnotationTypes(): MutableSet { - val supportedAnnotations = processor.getSupportedAnnotationTypes().toMutableSet() + val supportedAnnotations = processor.supportedAnnotationTypes.toMutableSet() supportedAnnotations.add("__gen.KotlinAptAnnotation") return supportedAnnotations } override fun getSupportedSourceVersion(): SourceVersion? { - return processor.getSupportedSourceVersion() + return processor.supportedSourceVersion } override fun process(annotations: MutableSet?, roundEnv: RoundEnvironment): Boolean { @@ -127,13 +127,13 @@ public abstract class AnnotationProcessorWrapper( } override fun getSupportedOptions(): MutableSet { - val supportedOptions = processor.getSupportedOptions().toHashSet() + val supportedOptions = processor.supportedOptions.toHashSet() supportedOptions.add(KAPT_ANNOTATION_OPTION) return supportedOptions } private fun ProcessingEnvironment.err(message: String) { - getMessager().printMessage(Diagnostic.Kind.ERROR, message) + messager.printMessage(Diagnostic.Kind.ERROR, message) } } \ No newline at end of file diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt index f52b9e79681..f0908fae6c6 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/RoundEnvironmentWrapper.kt @@ -17,18 +17,18 @@ internal class RoundEnvironmentWrapper( ) : RoundEnvironment { override fun getRootElements(): MutableSet? { - return parent.getRootElements() + return parent.rootElements } override fun getElementsAnnotatedWith(a: TypeElement): MutableSet? { val elements = parent.getElementsAnnotatedWith(a).toHashSet() - elements.addAll(resolveKotlinElements(a.getQualifiedName().toString())) + elements.addAll(resolveKotlinElements(a.qualifiedName.toString())) return elements } override fun getElementsAnnotatedWith(a: Class): MutableSet? { val elements = parent.getElementsAnnotatedWith(a).toHashSet() - elements.addAll(resolveKotlinElements(a.getName())) + elements.addAll(resolveKotlinElements(a.name)) return elements } @@ -37,24 +37,24 @@ internal class RoundEnvironmentWrapper( override fun errorRaised() = parent.errorRaised() private fun TypeElement.filterEnclosedElements(kind: ElementKind, name: String): List { - return getEnclosedElements().filter { it.getKind() == kind && it.getSimpleName().toString() == name } + return enclosedElements.filter { it.kind == kind && it.simpleName.toString() == name } } private fun TypeElement.filterEnclosedElements(kind: ElementKind): List { - return getEnclosedElements().filter { it.getKind() == kind } + return enclosedElements.filter { it.kind == kind } } private fun Element.hasAnnotation(annotationFqName: String): Boolean { - return getAnnotationMirrors().any { annotationFqName == it.getAnnotationType().asElement().toString() } + return annotationMirrors.any { annotationFqName == it.annotationType.asElement().toString() } } private fun TypeElement.hasInheritedAnnotation(annotationFqName: String): Boolean { if (hasAnnotation(annotationFqName)) return true - val superclassMirror = getSuperclass() + val superclassMirror = superclass if (superclassMirror is NoType) return false - val superClass = processingEnv.getTypeUtils().asElement(superclassMirror) + val superClass = processingEnv.typeUtils.asElement(superclassMirror) if (superClass !is TypeElement) return false return superClass.hasInheritedAnnotation(annotationFqName) @@ -65,7 +65,7 @@ internal class RoundEnvironmentWrapper( val descriptors = kotlinAnnotationsProvider.annotatedKotlinElements.get(annotationFqName) ?: setOf() val descriptorsWithKotlin = descriptors.fold(hashSetOf()) { set, descriptor -> - val clazz = processingEnv.getElementUtils().getTypeElement(descriptor.classFqName) ?: return@fold set + val clazz = processingEnv.elementUtils.getTypeElement(descriptor.classFqName) ?: return@fold set when (descriptor) { is AnnotatedClassDescriptor -> set.add(clazz) is AnnotatedConstructorDescriptor -> { @@ -85,12 +85,12 @@ internal class RoundEnvironmentWrapper( } if (kotlinAnnotationsProvider.supportInheritedAnnotations) { - val isInherited = processingEnv.getElementUtils().getTypeElement(annotationFqName) - ?.hasAnnotation(Inherited::class.java.getCanonicalName()) ?: false + val isInherited = processingEnv.elementUtils.getTypeElement(annotationFqName) + ?.hasAnnotation(Inherited::class.java.canonicalName) ?: false if (isInherited) { kotlinAnnotationsProvider.kotlinClasses.forEach { classFqName -> - val clazz = processingEnv.getElementUtils().getTypeElement(classFqName) ?: return@forEach + val clazz = processingEnv.elementUtils.getTypeElement(classFqName) ?: return@forEach if (clazz.hasInheritedAnnotation(annotationFqName)) { descriptorsWithKotlin.add(clazz) } diff --git a/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt b/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt index c5d0a547662..2995e88ff6a 100644 --- a/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt +++ b/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt @@ -54,7 +54,7 @@ public class AnnotationListParseTest { val annotationsFile = File(resourcesRootFile, "$testName/annotations.txt") val expectedFile = File(resourcesRootFile, "$testName/parsed.txt") - assertTrue(annotationsFile.getAbsolutePath() + " does not exist.", annotationsFile.exists()) + assertTrue(annotationsFile.absolutePath + " does not exist.", annotationsFile.exists()) val annotationProvider = FileKotlinAnnotationProvider(annotationsFile) val parsedAnnotations = annotationProvider.annotatedKotlinElements diff --git a/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt b/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt index 6d86c75cbb7..97332ef58b9 100644 --- a/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt +++ b/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt @@ -71,9 +71,9 @@ public class CompilerSmokeTest { return text } - val stdout = process.getInputStream()!!.readFully() + val stdout = process.inputStream!!.readFully() System.out.println(stdout) - val stderr = process.getErrorStream()!!.readFully() + val stderr = process.errorStream!!.readFully() System.err.println(stderr) val result = process.waitFor() diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 119a236f5db..c1dc7069c3d 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -41,18 +41,18 @@ abstract class AbstractKotlinCompile() : AbstractCo abstract protected fun populateTargetSpecificArgs(args: T) public var kotlinOptions: T = createBlankArgs() - public var kotlinDestinationDir: File? = getDestinationDir() + public var kotlinDestinationDir: File? = destinationDir - private val logger = Logging.getLogger(this.javaClass) - override fun getLogger() = logger + private val loggerInstance = Logging.getLogger(this.javaClass) + override fun getLogger() = loggerInstance @TaskAction override fun compile() { - getLogger().debug("Starting ${javaClass} task") + logger.debug("Starting ${javaClass} task") val args = createBlankArgs() val sources = getKotlinSources() if (sources.isEmpty()) { - getLogger().warn("No Kotlin files found, skipping Kotlin compiler task") + logger.warn("No Kotlin files found, skipping Kotlin compiler task") return } @@ -65,14 +65,14 @@ abstract class AbstractKotlinCompile() : AbstractCo private fun getKotlinSources(): List = (getSource() as Iterable).filter { it.isKotlinFile() } private fun File.isKotlinFile(): Boolean { - return when (FilenameUtils.getExtension(getName()).toLowerCase()) { + return when (FilenameUtils.getExtension(name).toLowerCase()) { "kt", "kts" -> true else -> false } } private fun populateCommonArgs(args: T, sources: List) { - args.freeArgs = sources.map { it.getAbsolutePath() } + args.freeArgs = sources.map { it.absolutePath } args.suppressWarnings = kotlinOptions.suppressWarnings args.verbose = kotlinOptions.verbose args.version = kotlinOptions.version @@ -80,8 +80,8 @@ abstract class AbstractKotlinCompile() : AbstractCo } private fun callCompiler(args: T) { - val messageCollector = GradleMessageCollector(getLogger()) - getLogger().debug("Calling compiler") + val messageCollector = GradleMessageCollector(logger) + logger.debug("Calling compiler") val exitCode = compiler.exec(messageCollector, Services.EMPTY, args) when (exitCode) { @@ -108,31 +108,31 @@ public open class KotlinCompile() : AbstractKotlinCompile>("compilerPluginClasspaths") ?: arrayOf() - getLogger().kotlinDebug("args.pluginClasspaths = ${args.pluginClasspaths.joinToString(File.pathSeparator)}") + logger.kotlinDebug("args.pluginClasspaths = ${args.pluginClasspaths.joinToString(File.pathSeparator)}") val basePluginOptions = extraProperties.getOrNull>("compilerPluginArguments") ?: arrayOf() val pluginOptions = arrayListOf(*basePluginOptions) handleKaptProperties(extraProperties, pluginOptions) args.pluginOptions = pluginOptions.toTypedArray() - getLogger().kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}") + logger.kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}") args.noStdlib = true args.noJdk = kotlinOptions.noJdk @@ -160,19 +160,19 @@ public open class KotlinCompile() : AbstractKotlinCompile) { val kaptAnnotationsFile = extraProperties.getOrNull("kaptAnnotationsFile") if (kaptAnnotationsFile != null) { if (kaptAnnotationsFile.exists()) kaptAnnotationsFile.delete() - pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:output=" + kaptAnnotationsFile) + pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:output=$kaptAnnotationsFile") } val kaptClassFileStubsDir = extraProperties.getOrNull("kaptStubsDir") if (kaptClassFileStubsDir != null) { - pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir) + pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=$kaptClassFileStubsDir") } val supportInheritedAnnotations = extraProperties.getOrNull("kaptInheritedAnnotations") @@ -191,12 +191,12 @@ public open class KotlinCompile() : AbstractKotlinCompile if (prevValue != null) javaTask.logger.warn("Destination for generated sources was modified by kapt. Previous value = $prevValue") - outputDir.getAbsolutePath() + outputDir.absolutePath } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/KotlinSourceSet.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/KotlinSourceSet.kt index 79c74d31a5b..e57146f9f8f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/KotlinSourceSet.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/KotlinSourceSet.kt @@ -19,7 +19,7 @@ open class KotlinSourceSetImpl(displayName: String?, resolver: FileResolver?): K private val kotlin: DefaultSourceDirectorySet = DefaultSourceDirectorySet(displayName + " Kotlin source", resolver) init { - kotlin.getFilter()?.include("**/*.java", "**/*.kt") + kotlin.filter?.include("**/*.java", "**/*.kt") } override fun getKotlin(): SourceDirectorySet { diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KaptExtension.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KaptExtension.kt index 6dda5469d6c..1bfce13241d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KaptExtension.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KaptExtension.kt @@ -54,8 +54,8 @@ public open class KaptAdditionalArgumentsDelegate( } fun execute(closure: Closure<*>) { - closure.setResolveStrategy(Closure.DELEGATE_FIRST) - closure.setDelegate(this) + closure.resolveStrategy = Closure.DELEGATE_FIRST + closure.delegate = this closure.call() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt index bd214aa9277..fafda92c197 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt @@ -50,13 +50,13 @@ abstract class KotlinSourceSetProcessor( abstract protected fun doTargetSpecificProcessing() val logger = Logging.getLogger(this.javaClass) - protected val sourceSetName: String = sourceSet.getName() + protected val sourceSetName: String = sourceSet.name protected val sourceRootDir: String = "src/${sourceSetName}/kotlin" - protected val absoluteSourceRootDir: String = project.getProjectDir().getPath() + "/" + sourceRootDir + protected val absoluteSourceRootDir: String = project.projectDir.path + "/" + sourceRootDir protected val kotlinSourceSet: KotlinSourceSet? by lazy { createKotlinSourceSet() } protected val kotlinDirSet: SourceDirectorySet? by lazy { createKotlinDirSet() } protected val kotlinTask: T by lazy { createKotlinCompileTask() } - protected val kotlinTaskName: String by lazy { kotlinTask.getName() } + protected val kotlinTaskName: String by lazy { kotlinTask.name } public fun run() { if (kotlinSourceSet == null || kotlinDirSet == null) { @@ -70,8 +70,8 @@ abstract class KotlinSourceSetProcessor( open protected fun createKotlinSourceSet(): KotlinSourceSet? = if (sourceSet is HasConvention) { logger.kotlinDebug("Creating KotlinSourceSet for source set ${sourceSet}") - val kotlinSourceSet = KotlinSourceSetImpl(sourceSet.getName(), project.getFileResolver()) - sourceSet.getConvention().getPlugins().put(pluginName, kotlinSourceSet) + val kotlinSourceSet = KotlinSourceSetImpl(sourceSet.name, project.fileResolver) + sourceSet.convention.plugins.put(pluginName, kotlinSourceSet) kotlinSourceSet } else { null @@ -79,30 +79,30 @@ abstract class KotlinSourceSetProcessor( open protected fun createKotlinDirSet(): SourceDirectorySet? { val srcDir = project.file(sourceRootDir) - logger.kotlinDebug("Creating Kotlin SourceDirectorySet for source set ${kotlinSourceSet} with src dir ${srcDir}") + logger.kotlinDebug("Creating Kotlin SourceDirectorySet for source set $kotlinSourceSet with src dir $srcDir") val kotlinDirSet = kotlinSourceSet?.getKotlin() kotlinDirSet?.srcDir(srcDir) return kotlinDirSet } open protected fun addSourcesToKotlinDirSet() { - logger.kotlinDebug("Adding Kotlin SourceDirectorySet ${kotlinDirSet} to source set ${sourceSet}") + logger.kotlinDebug("Adding Kotlin SourceDirectorySet $kotlinDirSet to source set $sourceSet") sourceSet.getAllJava()?.source(kotlinDirSet) sourceSet.getAllSource()?.source(kotlinDirSet) - sourceSet.getResources()?.getFilter()?.exclude { kotlinDirSet!!.contains(it.getFile()) } + sourceSet.resources?.filter?.exclude { kotlinDirSet!!.contains(it.file) } } open protected fun createKotlinCompileTask(suffix: String = ""): T { val name = sourceSet.getCompileTaskName(compileTaskNameSuffix) + suffix logger.kotlinDebug("Creating kotlin compile task $name with class $compilerClass") - val compile = project.getTasks().create(name, compilerClass) + val compile = project.tasks.create(name, compilerClass) compile.extensions.extraProperties.set("defaultModuleName", "${project.name}-$name") return compile } open protected fun commonTaskConfiguration() { javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask) - kotlinTask.setDescription(taskDescription) + kotlinTask.description = taskDescription kotlinTask.source(kotlinDirSet) } } @@ -127,10 +127,10 @@ class Kotlin2JvmSourceSetProcessor( override fun doTargetSpecificProcessing() { // store kotlin classes in separate directory. They will serve as class-path to java compiler - val kotlinDestinationDir = File(project.getBuildDir(), "kotlin-classes/${sourceSetName}") + val kotlinDestinationDir = File(project.buildDir, "kotlin-classes/${sourceSetName}") kotlinTask.setProperty("kotlinDestinationDir", kotlinDestinationDir) - val javaTask = project.getTasks().findByName(sourceSet.getCompileJavaTaskName()) as AbstractCompile? + val javaTask = project.tasks.findByName(sourceSet.compileJavaTaskName) as AbstractCompile? if (javaTask != null) { javaTask.dependsOn(kotlinTaskName) @@ -140,24 +140,24 @@ class Kotlin2JvmSourceSetProcessor( } val kotlinAnnotationProcessingDep = cachedKotlinAnnotationProcessingDep ?: run { - val projectVersion = loadKotlinVersionFromResource(project.getLogger()) + val projectVersion = loadKotlinVersionFromResource(project.logger) val dep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion" cachedKotlinAnnotationProcessingDep = dep dep } - val aptConfiguration = project.createAptConfiguration(sourceSet.getName(), kotlinAnnotationProcessingDep) + val aptConfiguration = project.createAptConfiguration(sourceSet.name, kotlinAnnotationProcessingDep) project.afterEvaluate { project -> if (project != null) { - for (dir in sourceSet.getJava().getSrcDirs()) { + for (dir in sourceSet.getJava().srcDirs) { kotlinDirSet?.srcDir(dir) } val subpluginEnvironment = loadSubplugins(project) subpluginEnvironment.addSubpluginArguments(project, kotlinTask) - if (aptConfiguration.getDependencies().size > 1 && javaTask is JavaCompile) { + if (aptConfiguration.dependencies.size > 1 && javaTask is JavaCompile) { val (aptOutputDir, aptWorkingDir) = project.getAptDirsForSourceSet(sourceSetName) val kaptManager = AnnotationProcessingManager(kotlinTask, javaTask, sourceSetName, @@ -170,7 +170,7 @@ class Kotlin2JvmSourceSetProcessor( if (kotlinAfterJavaTask != null) { javaTask.doFirst { - kotlinAfterJavaTask.setClasspath(project.files(kotlinTask.getClasspath(), javaTask.getDestinationDir())) + kotlinAfterJavaTask.classpath = project.files(kotlinTask.classpath, javaTask.destinationDir) } } } @@ -194,17 +194,17 @@ class Kotlin2JsSourceSetProcessor( ) { val copyKotlinJsTaskName = sourceSet.getTaskName("copy", "kotlinJs") - val clean = project.getTasks().findByName("clean") - val build = project.getTasks().findByName("build") + val clean = project.tasks.findByName("clean") + val build = project.tasks.findByName("build") - val defaultKotlinDestinationDir = File(project.getBuildDir(), "kotlin2js/${sourceSetName}") + val defaultKotlinDestinationDir = File(project.buildDir, "kotlin2js/${sourceSetName}") private fun kotlinTaskDestinationDir(): File? = kotlinTask.property("kotlinDestinationDir") as File? private fun kotlinJsDestinationDir(): File? = (kotlinTask.property("outputFile") as String).let { File(it).directory } private fun kotlinSourcePathsForSourceMap() = sourceSet.getAllSource() .map { it.path } .filter { it.endsWith(".kt") } - .map { it.replace(absoluteSourceRootDir, (kotlinTask.property("sourceMapDestinationDir") as File).getPath()) } + .map { it.replace(absoluteSourceRootDir, (kotlinTask.property("sourceMapDestinationDir") as File).path) } private fun shouldGenerateSourceMap() = kotlinTask.property("sourceMap") @@ -218,7 +218,7 @@ class Kotlin2JsSourceSetProcessor( private fun createCleanSourceMapTask() { val taskName = sourceSet.getTaskName("clean", "sourceMap") - val task = project.getTasks().create(taskName, Delete::class.java) + val task = project.tasks.create(taskName, Delete::class.java) task.onlyIf { kotlinTask.property("sourceMap") as Boolean } task.delete(object : Closure(this) { override fun call(): String? = (kotlinTask.property("outputFile") as String) + ".map" @@ -232,10 +232,10 @@ abstract class AbstractKotlinPlugin @Inject constructor(val scriptHandler: Scrip abstract fun buildSourceSetProcessor(project: ProjectInternal, javaBasePlugin: JavaBasePlugin, sourceSet: SourceSet): KotlinSourceSetProcessor<*> public override fun apply(project: Project) { - val javaBasePlugin = project.getPlugins().apply(JavaBasePlugin::class.java) - val javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention::class.java) + val javaBasePlugin = project.plugins.apply(JavaBasePlugin::class.java) + val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) - project.getPlugins().apply(JavaPlugin::class.java) + project.plugins.apply(JavaPlugin::class.java) configureSourceSetDefaults(project as ProjectInternal, javaBasePlugin, javaPluginConvention) } @@ -243,7 +243,7 @@ abstract class AbstractKotlinPlugin @Inject constructor(val scriptHandler: Scrip open protected fun configureSourceSetDefaults(project: ProjectInternal, javaBasePlugin: JavaBasePlugin, javaPluginConvention: JavaPluginConvention) { - javaPluginConvention.getSourceSets()?.all(Action { sourceSet -> + javaPluginConvention.sourceSets?.all(Action { sourceSet -> if (sourceSet != null) { buildSourceSetProcessor(project, javaBasePlugin, sourceSet).run() } @@ -276,7 +276,7 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand public override fun apply(p0: Project) { val project = p0 as ProjectInternal - val ext = project.getExtensions().getByName("android") as BaseExtension + val ext = project.extensions.getByName("android") as BaseExtension val version = loadAndroidPluginVersion() if (version != null) { @@ -291,16 +291,16 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand val projectVersion = loadKotlinVersionFromResource(log) val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion" - ext.getSourceSets().all(Action { sourceSet -> + ext.sourceSets.all(Action { sourceSet -> if (sourceSet is HasConvention) { - val sourceSetName = sourceSet.getName() - val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.getFileResolver()) - sourceSet.getConvention().getPlugins().put("kotlin", kotlinSourceSet) + val sourceSetName = sourceSet.name + val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.fileResolver) + sourceSet.convention.plugins.put("kotlin", kotlinSourceSet) val kotlinDirSet = kotlinSourceSet.getKotlin() - kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin")) + kotlinDirSet.srcDir(project.file("src/$sourceSetName/kotlin")) - aptConfigurations.put(sourceSet.getName(), - project.createAptConfiguration(sourceSet.getName(), kotlinAnnotationProcessingDep)) + aptConfigurations.put(sourceSet.name, + project.createAptConfiguration(sourceSet.name, kotlinAnnotationProcessingDep)) /*TODO: before 0.11 gradle android plugin there was: sourceSet.getAllJava().source(kotlinDirSet) @@ -310,11 +310,11 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand })) but those methods were removed so commented as temporary hack*/ - project.getLogger().kotlinDebug("Created kotlin sourceDirectorySet at ${kotlinDirSet.getSrcDirs()}") + project.logger.kotlinDebug("Created kotlin sourceDirectorySet at ${kotlinDirSet.srcDirs}") } }) - val extensions = (ext as ExtensionAware).getExtensions() + val extensions = (ext as ExtensionAware).extensions extensions.add("kotlinOptions", tasksProvider.kotlinJVMOptionsClass) AndroidGradleWrapper.setNoJdk(extensions.getByName("kotlinOptions")) @@ -322,11 +322,11 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand project.afterEvaluate { project -> if (project != null) { - val plugin = (project.getPlugins().findPlugin("android") - ?: project.getPlugins().findPlugin("android-library")) as BasePlugin + val plugin = (project.plugins.findPlugin("android") + ?: project.plugins.findPlugin("android-library")) as BasePlugin val variantManager = AndroidGradleWrapper.getVariantDataManager(plugin) - processVariantData(variantManager.getVariantDataList(), project, + processVariantData(variantManager.variantDataList, project, ext, plugin, aptConfigurations) } } @@ -339,13 +339,13 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand androidPlugin: BasePlugin, aptConfigurations: Map ) { - val logger = project.getLogger() + val logger = project.logger val kotlinOptions = getExtension(androidExt, "kotlinOptions") val subpluginEnvironment = loadSubplugins(project) for (variantData in variantDataList) { - val variantDataName = variantData.getName() + val variantDataName = variantData.name logger.kotlinDebug("Process variant [$variantDataName]") val javaTask = AndroidGradleWrapper.getJavaCompile(variantData) @@ -363,24 +363,24 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand } // store kotlin classes in separate directory. They will serve as class-path to java compiler - val kotlinOutputDir = File(project.getBuildDir(), "tmp/kotlin-classes/${variantDataName}") + val kotlinOutputDir = File(project.buildDir, "tmp/kotlin-classes/${variantDataName}") kotlinTask.setProperty("kotlinDestinationDir", kotlinOutputDir) - kotlinTask.setDestinationDir(javaTask.getDestinationDir()) - kotlinTask.setDescription("Compiles the ${variantDataName} kotlin.") - kotlinTask.setClasspath(javaTask.getClasspath()) - kotlinTask.setDependsOn(javaTask.getDependsOn()) + kotlinTask.destinationDir = javaTask.destinationDir + kotlinTask.description = "Compiles the ${variantDataName} kotlin." + kotlinTask.classpath = javaTask.classpath + kotlinTask.setDependsOn(javaTask.dependsOn) fun SourceDirectorySet.addSourceDirectories(additionalSourceFiles: Collection) { for (dir in additionalSourceFiles) { this.srcDir(dir) - logger.kotlinDebug("Source directory ${dir.getAbsolutePath()} was added to kotlin source for $kotlinTaskName") + logger.kotlinDebug("Source directory ${dir.absolutePath} was added to kotlin source for $kotlinTaskName") } } val aptFiles = arrayListOf() // getSortedSourceProviders should return only actual java sources, generated sources should be collected earlier - val providers = variantData.getVariantConfiguration().getSortedSourceProviders() + val providers = variantData.variantConfiguration.sortedSourceProviders for (provider in providers) { val javaSrcDirs = AndroidGradleWrapper.getJavaSrcDirs(provider as AndroidSourceSet) val kotlinSourceSet = getExtension(provider, "kotlin") @@ -389,9 +389,9 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand kotlinSourceDirectorySet.addSourceDirectories(javaSrcDirs) - val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).getName()] + val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).name] // Ignore if there's only an annotation processor wrapper in dependencies (added by default) - if (aptConfiguration != null && aptConfiguration.getDependencies().size > 1) { + if (aptConfiguration != null && aptConfiguration.dependencies.size > 1) { aptFiles.addAll(aptConfiguration.resolve()) } } @@ -402,18 +402,18 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand val additionalSourceFiles = AndroidGradleWrapper.getGeneratedSourceDirs(variantData) for (file in additionalSourceFiles) { kotlinTask.source(file) - logger.kotlinDebug("Source directory with generated files ${file.getAbsolutePath()} was added to kotlin source for $kotlinTaskName") + logger.kotlinDebug("Source directory with generated files ${file.absolutePath} was added to kotlin source for $kotlinTaskName") } subpluginEnvironment.addSubpluginArguments(project, kotlinTask) kotlinTask.doFirst { val androidRT = project.files(AndroidGradleWrapper.getRuntimeJars(androidPlugin, androidExt)) - val fullClasspath = (javaTask.getClasspath() + androidRT) - project.files(kotlinTask.property("kotlinDestinationDir")) - (it as AbstractCompile).setClasspath(fullClasspath) + val fullClasspath = (javaTask.classpath + androidRT) - project.files(kotlinTask.property("kotlinDestinationDir")) + (it as AbstractCompile).classpath = fullClasspath for (task in project.getTasksByName(kotlinTaskName + KOTLIN_AFTER_JAVA_TASK_SUFFIX, false)) { - (task as AbstractCompile).setClasspath(project.files(fullClasspath, javaTask.getDestinationDir())) + (task as AbstractCompile).classpath = project.files(fullClasspath, javaTask.destinationDir) } } @@ -434,19 +434,19 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand } javaTask.doFirst { - javaTask.setClasspath(javaTask.getClasspath() + project.files(kotlinTask.property("kotlinDestinationDir"))) + javaTask.classpath += project.files(kotlinTask.property("kotlinDestinationDir")) } } } fun getExtension(obj: Any, extensionName: String): T { if (obj is ExtensionAware) { - val result = obj.getExtensions().findByName(extensionName) + val result = obj.extensions.findByName(extensionName) if (result != null) { return result as T } } - val result = (obj as HasConvention).getConvention().getPlugins()[extensionName] + val result = (obj as HasConvention).convention.plugins[extensionName] return result as T } @@ -456,17 +456,17 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand private fun loadSubplugins(project: Project): SubpluginEnvironment { try { val subplugins = ServiceLoader.load( - KotlinGradleSubplugin::class.java, project.getBuildscript().getClassLoader()).toList() + KotlinGradleSubplugin::class.java, project.buildscript.classLoader).toList() val subpluginDependencyNames = subplugins.mapTo(hashSetOf()) { it.getGroupName() + ":" + it.getArtifactName() } - val classpath = project.getBuildscript().getConfigurations().getByName("classpath") + val classpath = project.buildscript.configurations.getByName("classpath") val subpluginClasspaths = hashMapOf>() for (subplugin in subplugins) { - val files = classpath.getDependencies() - .filter { subpluginDependencyNames.contains(it.getGroup() + ":" + it.getName()) } - .flatMap { classpath.files(it).map { it.getAbsolutePath() } } + val files = classpath.dependencies + .filter { subpluginDependencyNames.contains(it.group + ":" + it.name) } + .flatMap { classpath.files(it).map { it.absolutePath } } subpluginClasspaths.put(subplugin, files) } @@ -492,7 +492,7 @@ class SubpluginEnvironment( val args = subplugin.getExtraArguments(project, compileTask) with (subplugin) { - project.getLogger().kotlinDebug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.") + project.logger.kotlinDebug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.") } val subpluginClasspath = subpluginClasspaths[subplugin] @@ -513,16 +513,16 @@ class SubpluginEnvironment( open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInternal) { public fun resolveDependencies(vararg coordinates: String): Collection { - val dependencyHandler: DependencyHandler = scriptHandler.getDependencies() - val configurationsContainer: ConfigurationContainer = scriptHandler.getConfigurations() + val dependencyHandler: DependencyHandler = scriptHandler.dependencies + val configurationsContainer: ConfigurationContainer = scriptHandler.configurations val deps = coordinates.map { dependencyHandler.create(it) } val configuration = configurationsContainer.detachedConfiguration(*deps.toTypedArray()) - return configuration.getResolvedConfiguration().getFiles { true } + return configuration.resolvedConfiguration.getFiles { true } } - public fun kotlinPluginVersion(): String = project.getProperties()["kotlin.gradle.plugin.version"] as String + public fun kotlinPluginVersion(): String = project.properties["kotlin.gradle.plugin.version"] as String public fun kotlinPluginArtifactCoordinates(artifact: String): String = "org.jetbrains.kotlin:${artifact}:${kotlinPluginVersion()}" public fun kotlinJsLibraryCoordinates(): String = kotlinPluginArtifactCoordinates("kotlin-js-library") @@ -537,10 +537,10 @@ fun AbstractCompile.storeKaptAnnotationsFile(kapt: AnnotationProcessingManager) } private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair { - val aptOutputDir = File(getBuildDir(), "generated/source/kapt") + val aptOutputDir = File(buildDir, "generated/source/kapt") val aptOutputDirForVariant = File(aptOutputDir, sourceSetName) - val aptWorkingDir = File(getBuildDir(), "tmp/kapt") + val aptWorkingDir = File(buildDir, "tmp/kapt") val aptWorkingDirForVariant = File(aptWorkingDir, sourceSetName) return aptOutputDirForVariant to aptWorkingDirForVariant @@ -549,21 +549,21 @@ private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair { } val kotlinPluginVersion = loadKotlinVersionFromResource(log) - project.getExtensions().getExtraProperties()?.set("kotlin.gradle.plugin.version", kotlinPluginVersion) + project.extensions.extraProperties?.set("kotlin.gradle.plugin.version", kotlinPluginVersion) - val plugin = getPlugin(this.javaClass.getClassLoader(), sourceBuildScript) + val plugin = getPlugin(this.javaClass.classLoader, sourceBuildScript) plugin.apply(project) - project.getGradle().addBuildListener(FinishBuildListener(this.javaClass.getClassLoader(), startMemory)) + project.gradle.addBuildListener(FinishBuildListener(this.javaClass.classLoader, startMemory)) } protected abstract fun getPlugin(pluginClassLoader: ClassLoader, scriptHandler: ScriptHandler): Plugin @@ -46,16 +46,16 @@ abstract class KotlinBasePluginWrapper: Plugin { private fun findSourceBuildScript(project: Project): ScriptHandler? { log.kotlinDebug("Looking for proper script handler") var curProject = project - while (curProject != curProject.getParent()) { + while (curProject != curProject.parent) { log.kotlinDebug("Looking in project $project") - val scriptHandler = curProject.getBuildscript() - val found = scriptHandler.getConfigurations().findByName("classpath")?.firstOrNull { it.name.contains("kotlin-gradle-plugin") } != null + val scriptHandler = curProject.buildscript + val found = scriptHandler.configurations.findByName("classpath")?.firstOrNull { it.name.contains("kotlin-gradle-plugin") } != null if (found) { log.kotlinDebug("Found! returning...") return scriptHandler } log.kotlinDebug("not found, switching to parent") - curProject = curProject.getParent() ?: break + curProject = curProject.parent ?: break } return null } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt index 35a0754d790..b220f290b12 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt @@ -15,8 +15,8 @@ public class ThreadTracker { public fun checkThreadLeak(gradle: Gradle?) { try { val testThreads = gradle != null && - gradle.getRootProject().hasProperty("kotlin.gradle.test") && - !gradle.getRootProject().hasProperty("kotlin.gradle.noThreadTest") + gradle.rootProject.hasProperty("kotlin.gradle.test") && + !gradle.rootProject.hasProperty("kotlin.gradle.noThreadTest") Thread.sleep(if (testThreads) 200L else 50L) @@ -26,10 +26,10 @@ public class ThreadTracker { for (thread in after) { if (thread == Thread.currentThread()) continue - val name = thread.getName() + val name = thread.name if (testThreads) { - throw RuntimeException("Thread leaked: $thread: $name\n ${thread.getStackTrace().joinToString(separator = "\n", prefix = " at ")}") + throw RuntimeException("Thread leaked: $thread: $name\n ${thread.stackTrace.joinToString(separator = "\n", prefix = " at ")}") } else { log.info("Thread leaked: $thread: $name") diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/kotlinPluginVersion.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/kotlinPluginVersion.kt index d156b54ffd5..58e4738f085 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/kotlinPluginVersion.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/kotlinPluginVersion.kt @@ -24,7 +24,7 @@ internal fun Any.loadKotlinVersionFromResource(log: Logger): String { log.kotlinDebug("Loading version information") val props = Properties() val propFileName = "project.properties" - val inputStream = javaClass.getClassLoader()!!.getResourceAsStream(propFileName) + val inputStream = javaClass.classLoader!!.getResourceAsStream(propFileName) if (inputStream == null) { throw FileNotFoundException("property file '" + propFileName + "' not found in the classpath") diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/TasksProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/TasksProvider.kt index a739f60ec0c..2c317d58a6c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/TasksProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/TasksProvider.kt @@ -24,10 +24,10 @@ public open class KotlinTasksProvider(val tasksLoader: ClassLoader) { public fun createKotlinJVMTask(project: Project, name: String): AbstractCompile { - return project.getTasks().create(name, kotlinJVMCompileTaskClass) + return project.tasks.create(name, kotlinJVMCompileTaskClass) } public fun createKotlinJSTask(project: Project, name: String): AbstractCompile { - return project.getTasks().create(name, kotlinJSCompileTaskClass) + return project.tasks.create(name, kotlinJSCompileTaskClass) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index c247bbffa33..4ed54110b35 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -122,7 +122,7 @@ abstract class BaseGradleIT { } private fun Project.createBuildCommand(params: Array, options: BuildOptions): List { - val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath() + val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").absolutePath val tailParameters = params.asList() + listOf( pathToKotlinPlugin, if (options.withDaemon) "--daemon" else "--no-daemon", @@ -159,9 +159,9 @@ abstract class BaseGradleIT { return text } - val stdout = process.getInputStream()!!.readFully() + val stdout = process.inputStream!!.readFully() System.out.println(stdout) - val stderr = process.getErrorStream()!!.readFully() + val stderr = process.errorStream!!.readFully() System.err.println(stderr) val result = process.waitFor() @@ -169,9 +169,9 @@ abstract class BaseGradleIT { } fun copyRecursively(source: File, target: File) { - assertTrue(target.isDirectory()) - val targetFile = File(target, source.getName()) - if (source.isDirectory()) { + assertTrue(target.isDirectory) + val targetFile = File(target, source.name) + if (source.isDirectory) { targetFile.mkdir() source.listFiles()?.forEach { copyRecursively(it, targetFile) } } else { @@ -180,13 +180,13 @@ abstract class BaseGradleIT { } fun copyDirRecursively(source: File, target: File) { - assertTrue(source.isDirectory()) - assertTrue(target.isDirectory()) + assertTrue(source.isDirectory) + assertTrue(target.isDirectory) source.listFiles()?.forEach { copyRecursively(it, target) } } fun deleteRecursively(f: File): Unit { - if (f.isDirectory()) { + if (f.isDirectory) { f.listFiles()?.forEach { deleteRecursively(it) } val fileList = f.listFiles() if (fileList != null) {