Cleanup in libraries and tools: use property access syntax.
This commit is contained in:
+7
-7
@@ -11,7 +11,7 @@ import javax.tools.Diagnostic
|
|||||||
public class ExampleAnnotationProcessor : AbstractProcessor() {
|
public class ExampleAnnotationProcessor : AbstractProcessor() {
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.getCanonicalName()
|
val ANNOTATION_FQ_NAME = ExampleAnnotation::class.java.canonicalName
|
||||||
val SUFFIX_OPTION = "suffix"
|
val SUFFIX_OPTION = "suffix"
|
||||||
val GENERATE_KOTLIN_CODE_OPTION = "generate.kotlin.code"
|
val GENERATE_KOTLIN_CODE_OPTION = "generate.kotlin.code"
|
||||||
val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"
|
val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"
|
||||||
@@ -20,17 +20,17 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
|
|||||||
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||||
val elements = roundEnv.getElementsAnnotatedWith(ExampleAnnotation::class.java)
|
val elements = roundEnv.getElementsAnnotatedWith(ExampleAnnotation::class.java)
|
||||||
|
|
||||||
val elementUtils = processingEnv.getElementUtils()
|
val elementUtils = processingEnv.elementUtils
|
||||||
val filer = processingEnv.getFiler()
|
val filer = processingEnv.filer
|
||||||
|
|
||||||
val options = processingEnv.getOptions()
|
val options = processingEnv.options
|
||||||
val generatedFileSuffix = options[SUFFIX_OPTION] ?: "Generated"
|
val generatedFileSuffix = options[SUFFIX_OPTION] ?: "Generated"
|
||||||
val generateKotlinCode = "true" == options[GENERATE_KOTLIN_CODE_OPTION]
|
val generateKotlinCode = "true" == options[GENERATE_KOTLIN_CODE_OPTION]
|
||||||
val kotlinGenerated = options[KAPT_KOTLIN_GENERATED_OPTION]
|
val kotlinGenerated = options[KAPT_KOTLIN_GENERATED_OPTION]
|
||||||
|
|
||||||
for (element in elements) {
|
for (element in elements) {
|
||||||
val packageName = elementUtils.getPackageOf(element).getQualifiedName().toString()
|
val packageName = elementUtils.getPackageOf(element).qualifiedName.toString()
|
||||||
val simpleName = element.getSimpleName()
|
val simpleName = element.simpleName
|
||||||
val className = simpleName.toString().capitalize() + generatedFileSuffix
|
val className = simpleName.toString().capitalize() + generatedFileSuffix
|
||||||
|
|
||||||
filer.createSourceFile(className).openWriter().use { with(it) {
|
filer.createSourceFile(className).openWriter().use { with(it) {
|
||||||
@@ -38,7 +38,7 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
|
|||||||
appendln("public final class $className {}")
|
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 {
|
File(kotlinGenerated, "$simpleName.kt").writer().buffered().use {
|
||||||
it.appendln("package $packageName")
|
it.appendln("package $packageName")
|
||||||
it.appendln("fun $simpleName.customToString() = \"$simpleName: \" + toString()")
|
it.appendln("fun $simpleName.customToString() = \"$simpleName: \" + toString()")
|
||||||
|
|||||||
+2
-2
@@ -11,11 +11,11 @@ open class SampleTest {
|
|||||||
open val driver: WebDriver = HtmlUnitDriver(true)
|
open val driver: WebDriver = HtmlUnitDriver(true)
|
||||||
|
|
||||||
@test fun homePage(): Unit {
|
@test fun homePage(): Unit {
|
||||||
driver.get("file://" + File("sample.html").getCanonicalPath())
|
driver.get("file://" + File("sample.html").canonicalPath)
|
||||||
Thread.sleep(1000)
|
Thread.sleep(1000)
|
||||||
|
|
||||||
val foo = driver.findElement(By.id("foo"))!!
|
val foo = driver.findElement(By.id("foo"))!!
|
||||||
val text = foo.getText() ?: ""
|
val text = foo.text ?: ""
|
||||||
println("Found $foo with text '$text'")
|
println("Found $foo with text '$text'")
|
||||||
assertEquals("x=30 y=200 z=100 u=1000", text.trim())
|
assertEquals("x=30 y=200 z=100 u=1000", text.trim())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ open class SampleTest {
|
|||||||
open val driver: WebDriver = HtmlUnitDriver(true)
|
open val driver: WebDriver = HtmlUnitDriver(true)
|
||||||
|
|
||||||
@test fun homePage(): Unit {
|
@test fun homePage(): Unit {
|
||||||
driver.get("file://" + File("sample.html").getCanonicalPath())
|
driver.get("file://" + File("sample.html").canonicalPath)
|
||||||
Thread.sleep(1000)
|
Thread.sleep(1000)
|
||||||
|
|
||||||
val foo = driver.findElement(By.id("foo"))!!
|
val foo = driver.findElement(By.id("foo"))!!
|
||||||
val text = foo.getText() ?: ""
|
val text = foo.text ?: ""
|
||||||
println("Found $foo with text '$text'")
|
println("Found $foo with text '$text'")
|
||||||
assertEquals("Some Dynamically Created Content!!!", text.trim())
|
assertEquals("Some Dynamically Created Content!!!", text.trim())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public inline fun <T> ReentrantReadWriteLock.read(action: () -> T): T {
|
|||||||
public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
|
public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
|
||||||
val rl = readLock()
|
val rl = readLock()
|
||||||
|
|
||||||
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
|
val readCount = if (writeHoldCount == 0) readHoldCount else 0
|
||||||
repeat(readCount) { rl.unlock() }
|
repeat(readCount) { rl.unlock() }
|
||||||
|
|
||||||
val wl = writeLock()
|
val wl = writeLock()
|
||||||
|
|||||||
@@ -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.")
|
@Deprecated("This property has unclear semantics and will be removed soon.")
|
||||||
public val File.directory: File
|
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.
|
* 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 {
|
public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long {
|
||||||
if (!exists()) {
|
if (!exists()) {
|
||||||
throw NoSuchFileException(file = this, reason = "The source file doesn't exist")
|
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")
|
throw IllegalArgumentException("Use copyRecursively to copy a directory $this")
|
||||||
} else if (dst.exists()) {
|
} else if (dst.exists()) {
|
||||||
if (!overwrite) {
|
if (!overwrite) {
|
||||||
throw FileAlreadyExistsException(file = this,
|
throw FileAlreadyExistsException(file = this,
|
||||||
other = dst,
|
other = dst,
|
||||||
reason = "The destination file already exists")
|
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,
|
// In this case file should be copied *into* this directory,
|
||||||
// no matter whether it is empty or not
|
// no matter whether it is empty or not
|
||||||
return copyTo(dst.resolve(name), overwrite, bufferSize)
|
return copyTo(dst.resolve(name), overwrite, bufferSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dst.getParentFile()?.mkdirs()
|
dst.parentFile?.mkdirs()
|
||||||
dst.delete()
|
dst.delete()
|
||||||
val input = FileInputStream(this)
|
val input = FileInputStream(this)
|
||||||
return input.use<FileInputStream, Long> {
|
return input.use<FileInputStream, Long> {
|
||||||
@@ -340,12 +340,12 @@ public fun File.copyRecursively(dst: File,
|
|||||||
} else {
|
} else {
|
||||||
val relPath = src.relativeTo(this)
|
val relPath = src.relativeTo(this)
|
||||||
val dstFile = File(dst, relPath)
|
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,
|
if (onError(dstFile, FileAlreadyExistsException(file = src,
|
||||||
other = dstFile,
|
other = dstFile,
|
||||||
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
|
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
|
||||||
return false
|
return false
|
||||||
} else if (src.isDirectory()) {
|
} else if (src.isDirectory) {
|
||||||
dstFile.mkdirs()
|
dstFile.mkdirs()
|
||||||
} else {
|
} else {
|
||||||
if (src.copyTo(dstFile, true) != src.length()) {
|
if (src.copyTo(dstFile, true) != src.length()) {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class C()
|
|||||||
|
|
||||||
class JavaClassTest() : TestCase() {
|
class JavaClassTest() : TestCase() {
|
||||||
fun testMe () {
|
fun testMe () {
|
||||||
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.getName())
|
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.name)
|
||||||
assertEquals("java.util.ArrayList", ArrayList::class.java.getName())
|
assertEquals("java.util.ArrayList", ArrayList::class.java.name)
|
||||||
assertEquals("testjc.C", C::class.java.getName())
|
assertEquals("testjc.C", C::class.java.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ class FileTreeWalkTest {
|
|||||||
val basedir = createTestFiles()
|
val basedir = createTestFiles()
|
||||||
try {
|
try {
|
||||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
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
|
it.relativeToOrSelf(basedir).invariantSeparatorsPath
|
||||||
}.toHashSet())
|
}.toHashSet())
|
||||||
} finally {
|
} finally {
|
||||||
@@ -145,7 +145,7 @@ class FileTreeWalkTest {
|
|||||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
||||||
val namesTopDown = HashSet<String>()
|
val namesTopDown = HashSet<String>()
|
||||||
fun enter(file: File) {
|
fun enter(file: File) {
|
||||||
assertTrue(file.isDirectory())
|
assertTrue(file.isDirectory)
|
||||||
for (child in file.listFiles()) {
|
for (child in file.listFiles()) {
|
||||||
if (child.name.endsWith("txt"))
|
if (child.name.endsWith("txt"))
|
||||||
child.delete()
|
child.delete()
|
||||||
@@ -168,7 +168,7 @@ class FileTreeWalkTest {
|
|||||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
||||||
val namesTopDown = HashSet<String>()
|
val namesTopDown = HashSet<String>()
|
||||||
fun enter(file: File) {
|
fun enter(file: File) {
|
||||||
assertTrue(file.isDirectory())
|
assertTrue(file.isDirectory)
|
||||||
for (child in file.listFiles()) {
|
for (child in file.listFiles()) {
|
||||||
if (child.name.endsWith("txt"))
|
if (child.name.endsWith("txt"))
|
||||||
child.delete()
|
child.delete()
|
||||||
@@ -287,7 +287,7 @@ class FileTreeWalkTest {
|
|||||||
failed.add(dir.name)
|
failed.add(dir.name)
|
||||||
}
|
}
|
||||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
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())
|
assertTrue(stack.isEmpty())
|
||||||
for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) {
|
for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) {
|
||||||
assertTrue(dirs.contains(File(fileName)), fileName)
|
assertTrue(dirs.contains(File(fileName)), fileName)
|
||||||
@@ -313,7 +313,7 @@ class FileTreeWalkTest {
|
|||||||
files.clear()
|
files.clear()
|
||||||
dirs.clear()
|
dirs.clear()
|
||||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
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())
|
assertTrue(stack.isEmpty())
|
||||||
assertEquals(setOf("1"), failed)
|
assertEquals(setOf("1"), failed)
|
||||||
assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs)
|
assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs)
|
||||||
@@ -335,7 +335,7 @@ class FileTreeWalkTest {
|
|||||||
val visited = HashSet<File>()
|
val visited = HashSet<File>()
|
||||||
val block: (File) -> Unit = {
|
val block: (File) -> Unit = {
|
||||||
assertTrue(!visited.contains(it), it.toString())
|
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)
|
visited.add(it)
|
||||||
}
|
}
|
||||||
basedir.walkTopDown().forEach(block)
|
basedir.walkTopDown().forEach(block)
|
||||||
@@ -353,7 +353,7 @@ class FileTreeWalkTest {
|
|||||||
val visited = HashSet<File>()
|
val visited = HashSet<File>()
|
||||||
val block: (File) -> Unit = {
|
val block: (File) -> Unit = {
|
||||||
assertTrue(!visited.contains(it), it.toString())
|
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)
|
visited.add(it)
|
||||||
}
|
}
|
||||||
basedir.walkTopDown().forEach(block)
|
basedir.walkTopDown().forEach(block)
|
||||||
@@ -376,7 +376,7 @@ class FileTreeWalkTest {
|
|||||||
val basedir1 = createTestFiles()
|
val basedir1 = createTestFiles()
|
||||||
try {
|
try {
|
||||||
basedir1.walkTopDown().forEach {
|
basedir1.walkTopDown().forEach {
|
||||||
if (it.isFile()) {
|
if (it.isFile) {
|
||||||
makeBackup(it)
|
makeBackup(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,7 +389,7 @@ class FileTreeWalkTest {
|
|||||||
val basedir2 = createTestFiles()
|
val basedir2 = createTestFiles()
|
||||||
try {
|
try {
|
||||||
basedir2.walkTopDown().forEach {
|
basedir2.walkTopDown().forEach {
|
||||||
if (it.isFile()) {
|
if (it.isFile) {
|
||||||
makeBackup(it)
|
makeBackup(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,7 +424,7 @@ class FileTreeWalkTest {
|
|||||||
val found = HashSet<File>()
|
val found = HashSet<File>()
|
||||||
for (file in basedir.walkTopDown()) {
|
for (file in basedir.walkTopDown()) {
|
||||||
if (file.name == ".git") {
|
if (file.name == ".git") {
|
||||||
found.add(file.getParentFile())
|
found.add(file.parentFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(3, found.size)
|
assertEquals(3, found.size)
|
||||||
|
|||||||
@@ -20,16 +20,16 @@ class FilesTest {
|
|||||||
@test fun testCreateTempDir() {
|
@test fun testCreateTempDir() {
|
||||||
val dirSuf = System.currentTimeMillis().toString()
|
val dirSuf = System.currentTimeMillis().toString()
|
||||||
val dir1 = createTempDir("temp", dirSuf)
|
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) {
|
assertFailsWith(IllegalArgumentException::class) {
|
||||||
createTempDir("a")
|
createTempDir("a")
|
||||||
}
|
}
|
||||||
|
|
||||||
val dir2 = createTempDir("temp")
|
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()
|
val dir3 = createTempDir()
|
||||||
assertTrue(dir3.exists() && dir3.isDirectory())
|
assertTrue(dir3.exists() && dir3.isDirectory)
|
||||||
|
|
||||||
dir1.delete()
|
dir1.delete()
|
||||||
dir2.delete()
|
dir2.delete()
|
||||||
@@ -63,10 +63,10 @@ class FilesTest {
|
|||||||
createTempFile("temp3", ".kt", dir)
|
createTempFile("temp3", ".kt", dir)
|
||||||
|
|
||||||
// This line works only with Kotlin File.listFiles(filter)
|
// 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)
|
assertEquals(2, result!!.size)
|
||||||
// This line works both with Kotlin File.listFiles(filter) and the same Java function because of SAM
|
// 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)
|
assertEquals(2, result2!!.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ class FilesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test fun copyToNameWithoutParent() {
|
@test fun copyToNameWithoutParent() {
|
||||||
val currentDir = File("").getAbsoluteFile()!!
|
val currentDir = File("").absoluteFile!!
|
||||||
val srcFile = createTempFile()
|
val srcFile = createTempFile()
|
||||||
val dstFile = createTempFile(directory = currentDir)
|
val dstFile = createTempFile(directory = currentDir)
|
||||||
try {
|
try {
|
||||||
@@ -474,7 +474,7 @@ class FilesTest {
|
|||||||
for (file in src.walkTopDown()) {
|
for (file in src.walkTopDown()) {
|
||||||
val dstFile = File(dst, file.relativeTo(src))
|
val dstFile = File(dst, file.relativeTo(src))
|
||||||
assertTrue(dstFile.exists())
|
assertTrue(dstFile.exists())
|
||||||
if (dstFile.isFile()) {
|
if (dstFile.isFile) {
|
||||||
assertEquals(file.readText(), dstFile.readText())
|
assertEquals(file.readText(), dstFile.readText())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -95,7 +95,7 @@ public abstract class AnnotationProcessorWrapper(
|
|||||||
return
|
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
|
val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null
|
||||||
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
|
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
|
||||||
FileKotlinAnnotationProvider(annotationsFile)
|
FileKotlinAnnotationProvider(annotationsFile)
|
||||||
@@ -108,13 +108,13 @@ public abstract class AnnotationProcessorWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getSupportedAnnotationTypes(): MutableSet<String> {
|
override fun getSupportedAnnotationTypes(): MutableSet<String> {
|
||||||
val supportedAnnotations = processor.getSupportedAnnotationTypes().toMutableSet()
|
val supportedAnnotations = processor.supportedAnnotationTypes.toMutableSet()
|
||||||
supportedAnnotations.add("__gen.KotlinAptAnnotation")
|
supportedAnnotations.add("__gen.KotlinAptAnnotation")
|
||||||
return supportedAnnotations
|
return supportedAnnotations
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSupportedSourceVersion(): SourceVersion? {
|
override fun getSupportedSourceVersion(): SourceVersion? {
|
||||||
return processor.getSupportedSourceVersion()
|
return processor.supportedSourceVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||||
@@ -127,13 +127,13 @@ public abstract class AnnotationProcessorWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getSupportedOptions(): MutableSet<String> {
|
override fun getSupportedOptions(): MutableSet<String> {
|
||||||
val supportedOptions = processor.getSupportedOptions().toHashSet()
|
val supportedOptions = processor.supportedOptions.toHashSet()
|
||||||
supportedOptions.add(KAPT_ANNOTATION_OPTION)
|
supportedOptions.add(KAPT_ANNOTATION_OPTION)
|
||||||
return supportedOptions
|
return supportedOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ProcessingEnvironment.err(message: String) {
|
private fun ProcessingEnvironment.err(message: String) {
|
||||||
getMessager().printMessage(Diagnostic.Kind.ERROR, message)
|
messager.printMessage(Diagnostic.Kind.ERROR, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
-12
@@ -17,18 +17,18 @@ internal class RoundEnvironmentWrapper(
|
|||||||
) : RoundEnvironment {
|
) : RoundEnvironment {
|
||||||
|
|
||||||
override fun getRootElements(): MutableSet<out Element>? {
|
override fun getRootElements(): MutableSet<out Element>? {
|
||||||
return parent.getRootElements()
|
return parent.rootElements
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getElementsAnnotatedWith(a: TypeElement): MutableSet<out Element>? {
|
override fun getElementsAnnotatedWith(a: TypeElement): MutableSet<out Element>? {
|
||||||
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
|
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
|
||||||
elements.addAll(resolveKotlinElements(a.getQualifiedName().toString()))
|
elements.addAll(resolveKotlinElements(a.qualifiedName.toString()))
|
||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getElementsAnnotatedWith(a: Class<out Annotation>): MutableSet<out Element>? {
|
override fun getElementsAnnotatedWith(a: Class<out Annotation>): MutableSet<out Element>? {
|
||||||
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
|
val elements = parent.getElementsAnnotatedWith(a).toHashSet()
|
||||||
elements.addAll(resolveKotlinElements(a.getName()))
|
elements.addAll(resolveKotlinElements(a.name))
|
||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,24 +37,24 @@ internal class RoundEnvironmentWrapper(
|
|||||||
override fun errorRaised() = parent.errorRaised()
|
override fun errorRaised() = parent.errorRaised()
|
||||||
|
|
||||||
private fun TypeElement.filterEnclosedElements(kind: ElementKind, name: String): List<Element> {
|
private fun TypeElement.filterEnclosedElements(kind: ElementKind, name: String): List<Element> {
|
||||||
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<Element> {
|
private fun TypeElement.filterEnclosedElements(kind: ElementKind): List<Element> {
|
||||||
return getEnclosedElements().filter { it.getKind() == kind }
|
return enclosedElements.filter { it.kind == kind }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Element.hasAnnotation(annotationFqName: String): Boolean {
|
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 {
|
private fun TypeElement.hasInheritedAnnotation(annotationFqName: String): Boolean {
|
||||||
if (hasAnnotation(annotationFqName)) return true
|
if (hasAnnotation(annotationFqName)) return true
|
||||||
|
|
||||||
val superclassMirror = getSuperclass()
|
val superclassMirror = superclass
|
||||||
if (superclassMirror is NoType) return false
|
if (superclassMirror is NoType) return false
|
||||||
|
|
||||||
val superClass = processingEnv.getTypeUtils().asElement(superclassMirror)
|
val superClass = processingEnv.typeUtils.asElement(superclassMirror)
|
||||||
if (superClass !is TypeElement) return false
|
if (superClass !is TypeElement) return false
|
||||||
|
|
||||||
return superClass.hasInheritedAnnotation(annotationFqName)
|
return superClass.hasInheritedAnnotation(annotationFqName)
|
||||||
@@ -65,7 +65,7 @@ internal class RoundEnvironmentWrapper(
|
|||||||
|
|
||||||
val descriptors = kotlinAnnotationsProvider.annotatedKotlinElements.get(annotationFqName) ?: setOf()
|
val descriptors = kotlinAnnotationsProvider.annotatedKotlinElements.get(annotationFqName) ?: setOf()
|
||||||
val descriptorsWithKotlin = descriptors.fold(hashSetOf<Element>()) { set, descriptor ->
|
val descriptorsWithKotlin = descriptors.fold(hashSetOf<Element>()) { set, descriptor ->
|
||||||
val clazz = processingEnv.getElementUtils().getTypeElement(descriptor.classFqName) ?: return@fold set
|
val clazz = processingEnv.elementUtils.getTypeElement(descriptor.classFqName) ?: return@fold set
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is AnnotatedClassDescriptor -> set.add(clazz)
|
is AnnotatedClassDescriptor -> set.add(clazz)
|
||||||
is AnnotatedConstructorDescriptor -> {
|
is AnnotatedConstructorDescriptor -> {
|
||||||
@@ -85,12 +85,12 @@ internal class RoundEnvironmentWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (kotlinAnnotationsProvider.supportInheritedAnnotations) {
|
if (kotlinAnnotationsProvider.supportInheritedAnnotations) {
|
||||||
val isInherited = processingEnv.getElementUtils().getTypeElement(annotationFqName)
|
val isInherited = processingEnv.elementUtils.getTypeElement(annotationFqName)
|
||||||
?.hasAnnotation(Inherited::class.java.getCanonicalName()) ?: false
|
?.hasAnnotation(Inherited::class.java.canonicalName) ?: false
|
||||||
|
|
||||||
if (isInherited) {
|
if (isInherited) {
|
||||||
kotlinAnnotationsProvider.kotlinClasses.forEach { classFqName ->
|
kotlinAnnotationsProvider.kotlinClasses.forEach { classFqName ->
|
||||||
val clazz = processingEnv.getElementUtils().getTypeElement(classFqName) ?: return@forEach
|
val clazz = processingEnv.elementUtils.getTypeElement(classFqName) ?: return@forEach
|
||||||
if (clazz.hasInheritedAnnotation(annotationFqName)) {
|
if (clazz.hasInheritedAnnotation(annotationFqName)) {
|
||||||
descriptorsWithKotlin.add(clazz)
|
descriptorsWithKotlin.add(clazz)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ public class AnnotationListParseTest {
|
|||||||
val annotationsFile = File(resourcesRootFile, "$testName/annotations.txt")
|
val annotationsFile = File(resourcesRootFile, "$testName/annotations.txt")
|
||||||
val expectedFile = File(resourcesRootFile, "$testName/parsed.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 annotationProvider = FileKotlinAnnotationProvider(annotationsFile)
|
||||||
val parsedAnnotations = annotationProvider.annotatedKotlinElements
|
val parsedAnnotations = annotationProvider.annotatedKotlinElements
|
||||||
|
|||||||
+2
-2
@@ -71,9 +71,9 @@ public class CompilerSmokeTest {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
val stdout = process.getInputStream()!!.readFully()
|
val stdout = process.inputStream!!.readFully()
|
||||||
System.out.println(stdout)
|
System.out.println(stdout)
|
||||||
val stderr = process.getErrorStream()!!.readFully()
|
val stderr = process.errorStream!!.readFully()
|
||||||
System.err.println(stderr)
|
System.err.println(stderr)
|
||||||
|
|
||||||
val result = process.waitFor()
|
val result = process.waitFor()
|
||||||
|
|||||||
+31
-31
@@ -41,18 +41,18 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
abstract protected fun populateTargetSpecificArgs(args: T)
|
abstract protected fun populateTargetSpecificArgs(args: T)
|
||||||
|
|
||||||
public var kotlinOptions: T = createBlankArgs()
|
public var kotlinOptions: T = createBlankArgs()
|
||||||
public var kotlinDestinationDir: File? = getDestinationDir()
|
public var kotlinDestinationDir: File? = destinationDir
|
||||||
|
|
||||||
private val logger = Logging.getLogger(this.javaClass)
|
private val loggerInstance = Logging.getLogger(this.javaClass)
|
||||||
override fun getLogger() = logger
|
override fun getLogger() = loggerInstance
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
override fun compile() {
|
override fun compile() {
|
||||||
getLogger().debug("Starting ${javaClass} task")
|
logger.debug("Starting ${javaClass} task")
|
||||||
val args = createBlankArgs()
|
val args = createBlankArgs()
|
||||||
val sources = getKotlinSources()
|
val sources = getKotlinSources()
|
||||||
if (sources.isEmpty()) {
|
if (sources.isEmpty()) {
|
||||||
getLogger().warn("No Kotlin files found, skipping Kotlin compiler task")
|
logger.warn("No Kotlin files found, skipping Kotlin compiler task")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +65,14 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
private fun getKotlinSources(): List<File> = (getSource() as Iterable<File>).filter { it.isKotlinFile() }
|
private fun getKotlinSources(): List<File> = (getSource() as Iterable<File>).filter { it.isKotlinFile() }
|
||||||
|
|
||||||
private fun File.isKotlinFile(): Boolean {
|
private fun File.isKotlinFile(): Boolean {
|
||||||
return when (FilenameUtils.getExtension(getName()).toLowerCase()) {
|
return when (FilenameUtils.getExtension(name).toLowerCase()) {
|
||||||
"kt", "kts" -> true
|
"kt", "kts" -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun populateCommonArgs(args: T, sources: List<File>) {
|
private fun populateCommonArgs(args: T, sources: List<File>) {
|
||||||
args.freeArgs = sources.map { it.getAbsolutePath() }
|
args.freeArgs = sources.map { it.absolutePath }
|
||||||
args.suppressWarnings = kotlinOptions.suppressWarnings
|
args.suppressWarnings = kotlinOptions.suppressWarnings
|
||||||
args.verbose = kotlinOptions.verbose
|
args.verbose = kotlinOptions.verbose
|
||||||
args.version = kotlinOptions.version
|
args.version = kotlinOptions.version
|
||||||
@@ -80,8 +80,8 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun callCompiler(args: T) {
|
private fun callCompiler(args: T) {
|
||||||
val messageCollector = GradleMessageCollector(getLogger())
|
val messageCollector = GradleMessageCollector(logger)
|
||||||
getLogger().debug("Calling compiler")
|
logger.debug("Calling compiler")
|
||||||
val exitCode = compiler.exec(messageCollector, Services.EMPTY, args)
|
val exitCode = compiler.exec(messageCollector, Services.EMPTY, args)
|
||||||
|
|
||||||
when (exitCode) {
|
when (exitCode) {
|
||||||
@@ -108,31 +108,31 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
|
|
||||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||||
// show kotlin compiler where to look for java source files
|
// show kotlin compiler where to look for java source files
|
||||||
args.freeArgs = (args.freeArgs + getJavaSourceRoots().map { it.getAbsolutePath() }).toSet().toList()
|
args.freeArgs = (args.freeArgs + getJavaSourceRoots().map { it.absolutePath }).toSet().toList()
|
||||||
getLogger().kotlinDebug("args.freeArgs = ${args.freeArgs}")
|
logger.kotlinDebug("args.freeArgs = ${args.freeArgs}")
|
||||||
|
|
||||||
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
||||||
args.classpath = getClasspath().filter({ it != null && it.exists() }).joinToString(File.pathSeparator)
|
args.classpath = classpath.filter({ it != null && it.exists() }).joinToString(File.pathSeparator)
|
||||||
getLogger().kotlinDebug("args.classpath = ${args.classpath}")
|
logger.kotlinDebug("args.classpath = ${args.classpath}")
|
||||||
}
|
}
|
||||||
|
|
||||||
args.destination = if (StringUtils.isEmpty(kotlinOptions.destination)) {
|
args.destination = if (StringUtils.isEmpty(kotlinOptions.destination)) {
|
||||||
kotlinDestinationDir?.getPath()
|
kotlinDestinationDir?.path
|
||||||
} else {
|
} else {
|
||||||
kotlinOptions.destination
|
kotlinOptions.destination
|
||||||
}
|
}
|
||||||
getLogger().kotlinDebug("args.destination = ${args.destination}")
|
logger.kotlinDebug("args.destination = ${args.destination}")
|
||||||
|
|
||||||
val extraProperties = getExtensions().getExtraProperties()
|
val extraProperties = extensions.extraProperties
|
||||||
args.pluginClasspaths = extraProperties.getOrNull<Array<String>>("compilerPluginClasspaths") ?: arrayOf()
|
args.pluginClasspaths = extraProperties.getOrNull<Array<String>>("compilerPluginClasspaths") ?: arrayOf()
|
||||||
getLogger().kotlinDebug("args.pluginClasspaths = ${args.pluginClasspaths.joinToString(File.pathSeparator)}")
|
logger.kotlinDebug("args.pluginClasspaths = ${args.pluginClasspaths.joinToString(File.pathSeparator)}")
|
||||||
val basePluginOptions = extraProperties.getOrNull<Array<String>>("compilerPluginArguments") ?: arrayOf()
|
val basePluginOptions = extraProperties.getOrNull<Array<String>>("compilerPluginArguments") ?: arrayOf()
|
||||||
|
|
||||||
val pluginOptions = arrayListOf(*basePluginOptions)
|
val pluginOptions = arrayListOf(*basePluginOptions)
|
||||||
handleKaptProperties(extraProperties, pluginOptions)
|
handleKaptProperties(extraProperties, pluginOptions)
|
||||||
|
|
||||||
args.pluginOptions = pluginOptions.toTypedArray()
|
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.noStdlib = true
|
||||||
args.noJdk = kotlinOptions.noJdk
|
args.noJdk = kotlinOptions.noJdk
|
||||||
@@ -160,19 +160,19 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
addFriendPathForTestTask(it)
|
addFriendPathForTestTask(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().kotlinDebug("args.moduleName = ${args.moduleName}")
|
logger.kotlinDebug("args.moduleName = ${args.moduleName}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
||||||
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
||||||
if (kaptAnnotationsFile != null) {
|
if (kaptAnnotationsFile != null) {
|
||||||
if (kaptAnnotationsFile.exists()) kaptAnnotationsFile.delete()
|
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<File>("kaptStubsDir")
|
val kaptClassFileStubsDir = extraProperties.getOrNull<File>("kaptStubsDir")
|
||||||
if (kaptClassFileStubsDir != null) {
|
if (kaptClassFileStubsDir != null) {
|
||||||
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=" + kaptClassFileStubsDir)
|
pluginOptions.add("plugin:$ANNOTATIONS_PLUGIN_NAME:stubs=$kaptClassFileStubsDir")
|
||||||
}
|
}
|
||||||
|
|
||||||
val supportInheritedAnnotations = extraProperties.getOrNull<Boolean>("kaptInheritedAnnotations")
|
val supportInheritedAnnotations = extraProperties.getOrNull<Boolean>("kaptInheritedAnnotations")
|
||||||
@@ -191,12 +191,12 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
private fun File.isJavaFile() = extension.equals(JavaFileType.INSTANCE.getDefaultExtension(), ignoreCase = true)
|
private fun File.isJavaFile() = extension.equals(JavaFileType.INSTANCE.getDefaultExtension(), ignoreCase = true)
|
||||||
|
|
||||||
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
override fun afterCompileHook(args: K2JVMCompilerArguments) {
|
||||||
getLogger().debug("Copying resulting files to classes")
|
logger.debug("Copying resulting files to classes")
|
||||||
|
|
||||||
// Copy kotlin classes to all classes directory
|
// Copy kotlin classes to all classes directory
|
||||||
val outputDirFile = File(args.destination!!)
|
val outputDirFile = File(args.destination!!)
|
||||||
if (outputDirFile.exists()) {
|
if (outputDirFile.exists()) {
|
||||||
FileUtils.copyDirectory(outputDirFile, getDestinationDir())
|
FileUtils.copyDirectory(outputDirFile, destinationDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
|||||||
fun findSrcDirRoot(file: File): File? {
|
fun findSrcDirRoot(file: File): File? {
|
||||||
for (source in srcDirsSources) {
|
for (source in srcDirsSources) {
|
||||||
if (source is SourceDirectorySet) {
|
if (source is SourceDirectorySet) {
|
||||||
for (root in source.getSrcDirs()) {
|
for (root in source.srcDirs) {
|
||||||
if (FileUtil.isAncestor(root, file, false)) {
|
if (FileUtil.isAncestor(root, file, false)) {
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun addLibraryFiles(vararg fs: File) {
|
public fun addLibraryFiles(vararg fs: File) {
|
||||||
val strs = fs.map { it.getPath() }.toTypedArray()
|
val strs = fs.map { it.path }.toTypedArray()
|
||||||
addLibraryFiles(*strs)
|
addLibraryFiles(*strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
|||||||
get() = kotlinOptions.sourceMap
|
get() = kotlinOptions.sourceMap
|
||||||
|
|
||||||
init {
|
init {
|
||||||
getOutputs().file(MethodClosure(this, "getOutputFile"))
|
outputs.file(MethodClosure(this, "getOutputFile"))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun populateTargetSpecificArgs(args: K2JSCompilerArguments) {
|
override fun populateTargetSpecificArgs(args: K2JSCompilerArguments) {
|
||||||
@@ -286,16 +286,16 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
|||||||
args.kjsm = kotlinOptions.kjsm
|
args.kjsm = kotlinOptions.kjsm
|
||||||
|
|
||||||
val kotlinJsLibsFromDependencies =
|
val kotlinJsLibsFromDependencies =
|
||||||
getProject().getConfigurations().getByName("compile")
|
project.configurations.getByName("compile")
|
||||||
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
|
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
|
||||||
.map { it.getAbsolutePath() }
|
.map { it.absolutePath }
|
||||||
|
|
||||||
args.libraryFiles = kotlinOptions.libraryFiles + kotlinJsLibsFromDependencies
|
args.libraryFiles = kotlinOptions.libraryFiles + kotlinJsLibsFromDependencies
|
||||||
args.target = kotlinOptions.target
|
args.target = kotlinOptions.target
|
||||||
args.sourceMap = kotlinOptions.sourceMap
|
args.sourceMap = kotlinOptions.sourceMap
|
||||||
|
|
||||||
if (args.outputFile == null) {
|
if (args.outputFile == null) {
|
||||||
throw GradleException("${getName()}.kotlinOptions.outputFile should be specified.")
|
throw GradleException("$name.kotlinOptions.outputFile should be specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val outputDir = File(args.outputFile).directory
|
val outputDir = File(args.outputFile).directory
|
||||||
@@ -305,8 +305,8 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().debug("${getName()} set libraryFiles to ${args.libraryFiles.joinToString(",")}")
|
logger.debug("$name set libraryFiles to ${args.libraryFiles.joinToString(",")}")
|
||||||
getLogger().debug("${getName()} set outputFile to ${args.outputFile}")
|
logger.debug("$name set outputFile to ${args.outputFile}")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -43,7 +43,7 @@ fun Project.initKapt(
|
|||||||
|
|
||||||
kotlinTask.logger.kotlinDebug("kapt: Using class file stubs")
|
kotlinTask.logger.kotlinDebug("kapt: Using class file stubs")
|
||||||
|
|
||||||
val stubsDir = File(getBuildDir(), "tmp/kapt/$variantName/classFileStubs")
|
val stubsDir = File(buildDir, "tmp/kapt/$variantName/classFileStubs")
|
||||||
kotlinTask.extensions.extraProperties.set("kaptStubsDir", stubsDir)
|
kotlinTask.extensions.extraProperties.set("kaptStubsDir", stubsDir)
|
||||||
|
|
||||||
javaTask.doFirst {
|
javaTask.doFirst {
|
||||||
@@ -217,7 +217,7 @@ public class AnnotationProcessingManager(
|
|||||||
getProcessorStubClassName(processorFqName),
|
getProcessorStubClassName(processorFqName),
|
||||||
taskQualifier) as File
|
taskQualifier) as File
|
||||||
|
|
||||||
project.getLogger().kotlinDebug("kapt: Wrapper for $processorFqName generated: $wrapperFile")
|
project.logger.kotlinDebug("kapt: Wrapper for $processorFqName generated: $wrapperFile")
|
||||||
}
|
}
|
||||||
|
|
||||||
val annotationProcessorWrapperFqNames = processorFqNames
|
val annotationProcessorWrapperFqNames = processorFqNames
|
||||||
@@ -251,7 +251,7 @@ public class AnnotationProcessingManager(
|
|||||||
javaTask.addCompilerArgument("-s") { prevValue ->
|
javaTask.addCompilerArgument("-s") { prevValue ->
|
||||||
if (prevValue != null)
|
if (prevValue != null)
|
||||||
javaTask.logger.warn("Destination for generated sources was modified by kapt. Previous value = $prevValue")
|
javaTask.logger.warn("Destination for generated sources was modified by kapt. Previous value = $prevValue")
|
||||||
outputDir.getAbsolutePath()
|
outputDir.absolutePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ open class KotlinSourceSetImpl(displayName: String?, resolver: FileResolver?): K
|
|||||||
private val kotlin: DefaultSourceDirectorySet = DefaultSourceDirectorySet(displayName + " Kotlin source", resolver)
|
private val kotlin: DefaultSourceDirectorySet = DefaultSourceDirectorySet(displayName + " Kotlin source", resolver)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
kotlin.getFilter()?.include("**/*.java", "**/*.kt")
|
kotlin.filter?.include("**/*.java", "**/*.kt")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getKotlin(): SourceDirectorySet {
|
override fun getKotlin(): SourceDirectorySet {
|
||||||
|
|||||||
+2
-2
@@ -54,8 +54,8 @@ public open class KaptAdditionalArgumentsDelegate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun execute(closure: Closure<*>) {
|
fun execute(closure: Closure<*>) {
|
||||||
closure.setResolveStrategy(Closure.DELEGATE_FIRST)
|
closure.resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
closure.setDelegate(this)
|
closure.delegate = this
|
||||||
closure.call()
|
closure.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+79
-79
@@ -50,13 +50,13 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
|
|||||||
abstract protected fun doTargetSpecificProcessing()
|
abstract protected fun doTargetSpecificProcessing()
|
||||||
val logger = Logging.getLogger(this.javaClass)
|
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 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 kotlinSourceSet: KotlinSourceSet? by lazy { createKotlinSourceSet() }
|
||||||
protected val kotlinDirSet: SourceDirectorySet? by lazy { createKotlinDirSet() }
|
protected val kotlinDirSet: SourceDirectorySet? by lazy { createKotlinDirSet() }
|
||||||
protected val kotlinTask: T by lazy { createKotlinCompileTask() }
|
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() {
|
public fun run() {
|
||||||
if (kotlinSourceSet == null || kotlinDirSet == null) {
|
if (kotlinSourceSet == null || kotlinDirSet == null) {
|
||||||
@@ -70,8 +70,8 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
|
|||||||
open protected fun createKotlinSourceSet(): KotlinSourceSet? =
|
open protected fun createKotlinSourceSet(): KotlinSourceSet? =
|
||||||
if (sourceSet is HasConvention) {
|
if (sourceSet is HasConvention) {
|
||||||
logger.kotlinDebug("Creating KotlinSourceSet for source set ${sourceSet}")
|
logger.kotlinDebug("Creating KotlinSourceSet for source set ${sourceSet}")
|
||||||
val kotlinSourceSet = KotlinSourceSetImpl(sourceSet.getName(), project.getFileResolver())
|
val kotlinSourceSet = KotlinSourceSetImpl(sourceSet.name, project.fileResolver)
|
||||||
sourceSet.getConvention().getPlugins().put(pluginName, kotlinSourceSet)
|
sourceSet.convention.plugins.put(pluginName, kotlinSourceSet)
|
||||||
kotlinSourceSet
|
kotlinSourceSet
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -79,30 +79,30 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
|
|||||||
|
|
||||||
open protected fun createKotlinDirSet(): SourceDirectorySet? {
|
open protected fun createKotlinDirSet(): SourceDirectorySet? {
|
||||||
val srcDir = project.file(sourceRootDir)
|
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()
|
val kotlinDirSet = kotlinSourceSet?.getKotlin()
|
||||||
kotlinDirSet?.srcDir(srcDir)
|
kotlinDirSet?.srcDir(srcDir)
|
||||||
return kotlinDirSet
|
return kotlinDirSet
|
||||||
}
|
}
|
||||||
|
|
||||||
open protected fun addSourcesToKotlinDirSet() {
|
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.getAllJava()?.source(kotlinDirSet)
|
||||||
sourceSet.getAllSource()?.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 {
|
open protected fun createKotlinCompileTask(suffix: String = ""): T {
|
||||||
val name = sourceSet.getCompileTaskName(compileTaskNameSuffix) + suffix
|
val name = sourceSet.getCompileTaskName(compileTaskNameSuffix) + suffix
|
||||||
logger.kotlinDebug("Creating kotlin compile task $name with class $compilerClass")
|
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")
|
compile.extensions.extraProperties.set("defaultModuleName", "${project.name}-$name")
|
||||||
return compile
|
return compile
|
||||||
}
|
}
|
||||||
|
|
||||||
open protected fun commonTaskConfiguration() {
|
open protected fun commonTaskConfiguration() {
|
||||||
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
||||||
kotlinTask.setDescription(taskDescription)
|
kotlinTask.description = taskDescription
|
||||||
kotlinTask.source(kotlinDirSet)
|
kotlinTask.source(kotlinDirSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,10 +127,10 @@ class Kotlin2JvmSourceSetProcessor(
|
|||||||
|
|
||||||
override fun doTargetSpecificProcessing() {
|
override fun doTargetSpecificProcessing() {
|
||||||
// store kotlin classes in separate directory. They will serve as class-path to java compiler
|
// 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)
|
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) {
|
if (javaTask != null) {
|
||||||
javaTask.dependsOn(kotlinTaskName)
|
javaTask.dependsOn(kotlinTaskName)
|
||||||
@@ -140,24 +140,24 @@ class Kotlin2JvmSourceSetProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val kotlinAnnotationProcessingDep = cachedKotlinAnnotationProcessingDep ?: run {
|
val kotlinAnnotationProcessingDep = cachedKotlinAnnotationProcessingDep ?: run {
|
||||||
val projectVersion = loadKotlinVersionFromResource(project.getLogger())
|
val projectVersion = loadKotlinVersionFromResource(project.logger)
|
||||||
val dep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion"
|
val dep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion"
|
||||||
cachedKotlinAnnotationProcessingDep = dep
|
cachedKotlinAnnotationProcessingDep = dep
|
||||||
dep
|
dep
|
||||||
}
|
}
|
||||||
|
|
||||||
val aptConfiguration = project.createAptConfiguration(sourceSet.getName(), kotlinAnnotationProcessingDep)
|
val aptConfiguration = project.createAptConfiguration(sourceSet.name, kotlinAnnotationProcessingDep)
|
||||||
|
|
||||||
project.afterEvaluate { project ->
|
project.afterEvaluate { project ->
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
for (dir in sourceSet.getJava().getSrcDirs()) {
|
for (dir in sourceSet.getJava().srcDirs) {
|
||||||
kotlinDirSet?.srcDir(dir)
|
kotlinDirSet?.srcDir(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
val subpluginEnvironment = loadSubplugins(project)
|
val subpluginEnvironment = loadSubplugins(project)
|
||||||
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
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 (aptOutputDir, aptWorkingDir) = project.getAptDirsForSourceSet(sourceSetName)
|
||||||
|
|
||||||
val kaptManager = AnnotationProcessingManager(kotlinTask, javaTask, sourceSetName,
|
val kaptManager = AnnotationProcessingManager(kotlinTask, javaTask, sourceSetName,
|
||||||
@@ -170,7 +170,7 @@ class Kotlin2JvmSourceSetProcessor(
|
|||||||
|
|
||||||
if (kotlinAfterJavaTask != null) {
|
if (kotlinAfterJavaTask != null) {
|
||||||
javaTask.doFirst {
|
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 copyKotlinJsTaskName = sourceSet.getTaskName("copy", "kotlinJs")
|
||||||
val clean = project.getTasks().findByName("clean")
|
val clean = project.tasks.findByName("clean")
|
||||||
val build = project.getTasks().findByName("build")
|
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 kotlinTaskDestinationDir(): File? = kotlinTask.property("kotlinDestinationDir") as File?
|
||||||
private fun kotlinJsDestinationDir(): File? = (kotlinTask.property("outputFile") as String).let { File(it).directory }
|
private fun kotlinJsDestinationDir(): File? = (kotlinTask.property("outputFile") as String).let { File(it).directory }
|
||||||
|
|
||||||
private fun kotlinSourcePathsForSourceMap() = sourceSet.getAllSource()
|
private fun kotlinSourcePathsForSourceMap() = sourceSet.getAllSource()
|
||||||
.map { it.path }
|
.map { it.path }
|
||||||
.filter { it.endsWith(".kt") }
|
.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")
|
private fun shouldGenerateSourceMap() = kotlinTask.property("sourceMap")
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ class Kotlin2JsSourceSetProcessor(
|
|||||||
|
|
||||||
private fun createCleanSourceMapTask() {
|
private fun createCleanSourceMapTask() {
|
||||||
val taskName = sourceSet.getTaskName("clean", "sourceMap")
|
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.onlyIf { kotlinTask.property("sourceMap") as Boolean }
|
||||||
task.delete(object : Closure<String>(this) {
|
task.delete(object : Closure<String>(this) {
|
||||||
override fun call(): String? = (kotlinTask.property("outputFile") as String) + ".map"
|
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<*>
|
abstract fun buildSourceSetProcessor(project: ProjectInternal, javaBasePlugin: JavaBasePlugin, sourceSet: SourceSet): KotlinSourceSetProcessor<*>
|
||||||
|
|
||||||
public override fun apply(project: Project) {
|
public override fun apply(project: Project) {
|
||||||
val javaBasePlugin = project.getPlugins().apply(JavaBasePlugin::class.java)
|
val javaBasePlugin = project.plugins.apply(JavaBasePlugin::class.java)
|
||||||
val javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention::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)
|
configureSourceSetDefaults(project as ProjectInternal, javaBasePlugin, javaPluginConvention)
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ abstract class AbstractKotlinPlugin @Inject constructor(val scriptHandler: Scrip
|
|||||||
open protected fun configureSourceSetDefaults(project: ProjectInternal,
|
open protected fun configureSourceSetDefaults(project: ProjectInternal,
|
||||||
javaBasePlugin: JavaBasePlugin,
|
javaBasePlugin: JavaBasePlugin,
|
||||||
javaPluginConvention: JavaPluginConvention) {
|
javaPluginConvention: JavaPluginConvention) {
|
||||||
javaPluginConvention.getSourceSets()?.all(Action<SourceSet> { sourceSet ->
|
javaPluginConvention.sourceSets?.all(Action<SourceSet> { sourceSet ->
|
||||||
if (sourceSet != null) {
|
if (sourceSet != null) {
|
||||||
buildSourceSetProcessor(project, javaBasePlugin, sourceSet).run()
|
buildSourceSetProcessor(project, javaBasePlugin, sourceSet).run()
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
public override fun apply(p0: Project) {
|
public override fun apply(p0: Project) {
|
||||||
|
|
||||||
val project = p0 as ProjectInternal
|
val project = p0 as ProjectInternal
|
||||||
val ext = project.getExtensions().getByName("android") as BaseExtension
|
val ext = project.extensions.getByName("android") as BaseExtension
|
||||||
|
|
||||||
val version = loadAndroidPluginVersion()
|
val version = loadAndroidPluginVersion()
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
@@ -291,16 +291,16 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
val projectVersion = loadKotlinVersionFromResource(log)
|
val projectVersion = loadKotlinVersionFromResource(log)
|
||||||
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion"
|
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$projectVersion"
|
||||||
|
|
||||||
ext.getSourceSets().all(Action<AndroidSourceSet> { sourceSet ->
|
ext.sourceSets.all(Action<AndroidSourceSet> { sourceSet ->
|
||||||
if (sourceSet is HasConvention) {
|
if (sourceSet is HasConvention) {
|
||||||
val sourceSetName = sourceSet.getName()
|
val sourceSetName = sourceSet.name
|
||||||
val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.getFileResolver())
|
val kotlinSourceSet = KotlinSourceSetImpl(sourceSetName, project.fileResolver)
|
||||||
sourceSet.getConvention().getPlugins().put("kotlin", kotlinSourceSet)
|
sourceSet.convention.plugins.put("kotlin", kotlinSourceSet)
|
||||||
val kotlinDirSet = kotlinSourceSet.getKotlin()
|
val kotlinDirSet = kotlinSourceSet.getKotlin()
|
||||||
kotlinDirSet.srcDir(project.file("src/${sourceSetName}/kotlin"))
|
kotlinDirSet.srcDir(project.file("src/$sourceSetName/kotlin"))
|
||||||
|
|
||||||
aptConfigurations.put(sourceSet.getName(),
|
aptConfigurations.put(sourceSet.name,
|
||||||
project.createAptConfiguration(sourceSet.getName(), kotlinAnnotationProcessingDep))
|
project.createAptConfiguration(sourceSet.name, kotlinAnnotationProcessingDep))
|
||||||
|
|
||||||
/*TODO: before 0.11 gradle android plugin there was:
|
/*TODO: before 0.11 gradle android plugin there was:
|
||||||
sourceSet.getAllJava().source(kotlinDirSet)
|
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*/
|
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)
|
extensions.add("kotlinOptions", tasksProvider.kotlinJVMOptionsClass)
|
||||||
AndroidGradleWrapper.setNoJdk(extensions.getByName("kotlinOptions"))
|
AndroidGradleWrapper.setNoJdk(extensions.getByName("kotlinOptions"))
|
||||||
|
|
||||||
@@ -322,11 +322,11 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
|
|
||||||
project.afterEvaluate { project ->
|
project.afterEvaluate { project ->
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
val plugin = (project.getPlugins().findPlugin("android")
|
val plugin = (project.plugins.findPlugin("android")
|
||||||
?: project.getPlugins().findPlugin("android-library")) as BasePlugin
|
?: project.plugins.findPlugin("android-library")) as BasePlugin
|
||||||
|
|
||||||
val variantManager = AndroidGradleWrapper.getVariantDataManager(plugin)
|
val variantManager = AndroidGradleWrapper.getVariantDataManager(plugin)
|
||||||
processVariantData(variantManager.getVariantDataList(), project,
|
processVariantData(variantManager.variantDataList, project,
|
||||||
ext, plugin, aptConfigurations)
|
ext, plugin, aptConfigurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -339,13 +339,13 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
androidPlugin: BasePlugin,
|
androidPlugin: BasePlugin,
|
||||||
aptConfigurations: Map<String, Configuration>
|
aptConfigurations: Map<String, Configuration>
|
||||||
) {
|
) {
|
||||||
val logger = project.getLogger()
|
val logger = project.logger
|
||||||
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
val kotlinOptions = getExtension<Any?>(androidExt, "kotlinOptions")
|
||||||
|
|
||||||
val subpluginEnvironment = loadSubplugins(project)
|
val subpluginEnvironment = loadSubplugins(project)
|
||||||
|
|
||||||
for (variantData in variantDataList) {
|
for (variantData in variantDataList) {
|
||||||
val variantDataName = variantData.getName()
|
val variantDataName = variantData.name
|
||||||
logger.kotlinDebug("Process variant [$variantDataName]")
|
logger.kotlinDebug("Process variant [$variantDataName]")
|
||||||
|
|
||||||
val javaTask = AndroidGradleWrapper.getJavaCompile(variantData)
|
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
|
// 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.setProperty("kotlinDestinationDir", kotlinOutputDir)
|
||||||
kotlinTask.setDestinationDir(javaTask.getDestinationDir())
|
kotlinTask.destinationDir = javaTask.destinationDir
|
||||||
kotlinTask.setDescription("Compiles the ${variantDataName} kotlin.")
|
kotlinTask.description = "Compiles the ${variantDataName} kotlin."
|
||||||
kotlinTask.setClasspath(javaTask.getClasspath())
|
kotlinTask.classpath = javaTask.classpath
|
||||||
kotlinTask.setDependsOn(javaTask.getDependsOn())
|
kotlinTask.setDependsOn(javaTask.dependsOn)
|
||||||
|
|
||||||
fun SourceDirectorySet.addSourceDirectories(additionalSourceFiles: Collection<File>) {
|
fun SourceDirectorySet.addSourceDirectories(additionalSourceFiles: Collection<File>) {
|
||||||
for (dir in additionalSourceFiles) {
|
for (dir in additionalSourceFiles) {
|
||||||
this.srcDir(dir)
|
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<File>()
|
val aptFiles = arrayListOf<File>()
|
||||||
|
|
||||||
// getSortedSourceProviders should return only actual java sources, generated sources should be collected earlier
|
// 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) {
|
for (provider in providers) {
|
||||||
val javaSrcDirs = AndroidGradleWrapper.getJavaSrcDirs(provider as AndroidSourceSet)
|
val javaSrcDirs = AndroidGradleWrapper.getJavaSrcDirs(provider as AndroidSourceSet)
|
||||||
val kotlinSourceSet = getExtension<KotlinSourceSet>(provider, "kotlin")
|
val kotlinSourceSet = getExtension<KotlinSourceSet>(provider, "kotlin")
|
||||||
@@ -389,9 +389,9 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
|
|
||||||
kotlinSourceDirectorySet.addSourceDirectories(javaSrcDirs)
|
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)
|
// 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())
|
aptFiles.addAll(aptConfiguration.resolve())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,18 +402,18 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
val additionalSourceFiles = AndroidGradleWrapper.getGeneratedSourceDirs(variantData)
|
val additionalSourceFiles = AndroidGradleWrapper.getGeneratedSourceDirs(variantData)
|
||||||
for (file in additionalSourceFiles) {
|
for (file in additionalSourceFiles) {
|
||||||
kotlinTask.source(file)
|
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)
|
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
||||||
|
|
||||||
kotlinTask.doFirst {
|
kotlinTask.doFirst {
|
||||||
val androidRT = project.files(AndroidGradleWrapper.getRuntimeJars(androidPlugin, androidExt))
|
val androidRT = project.files(AndroidGradleWrapper.getRuntimeJars(androidPlugin, androidExt))
|
||||||
val fullClasspath = (javaTask.getClasspath() + androidRT) - project.files(kotlinTask.property("kotlinDestinationDir"))
|
val fullClasspath = (javaTask.classpath + androidRT) - project.files(kotlinTask.property("kotlinDestinationDir"))
|
||||||
(it as AbstractCompile).setClasspath(fullClasspath)
|
(it as AbstractCompile).classpath = fullClasspath
|
||||||
|
|
||||||
for (task in project.getTasksByName(kotlinTaskName + KOTLIN_AFTER_JAVA_TASK_SUFFIX, false)) {
|
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.doFirst {
|
||||||
javaTask.setClasspath(javaTask.getClasspath() + project.files(kotlinTask.property("kotlinDestinationDir")))
|
javaTask.classpath += project.files(kotlinTask.property("kotlinDestinationDir"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> getExtension(obj: Any, extensionName: String): T {
|
fun <T> getExtension(obj: Any, extensionName: String): T {
|
||||||
if (obj is ExtensionAware) {
|
if (obj is ExtensionAware) {
|
||||||
val result = obj.getExtensions().findByName(extensionName)
|
val result = obj.extensions.findByName(extensionName)
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result as T
|
return result as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val result = (obj as HasConvention).getConvention().getPlugins()[extensionName]
|
val result = (obj as HasConvention).convention.plugins[extensionName]
|
||||||
return result as T
|
return result as T
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,17 +456,17 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
|||||||
private fun loadSubplugins(project: Project): SubpluginEnvironment {
|
private fun loadSubplugins(project: Project): SubpluginEnvironment {
|
||||||
try {
|
try {
|
||||||
val subplugins = ServiceLoader.load(
|
val subplugins = ServiceLoader.load(
|
||||||
KotlinGradleSubplugin::class.java, project.getBuildscript().getClassLoader()).toList()
|
KotlinGradleSubplugin::class.java, project.buildscript.classLoader).toList()
|
||||||
val subpluginDependencyNames =
|
val subpluginDependencyNames =
|
||||||
subplugins.mapTo(hashSetOf<String>()) { it.getGroupName() + ":" + it.getArtifactName() }
|
subplugins.mapTo(hashSetOf<String>()) { it.getGroupName() + ":" + it.getArtifactName() }
|
||||||
|
|
||||||
val classpath = project.getBuildscript().getConfigurations().getByName("classpath")
|
val classpath = project.buildscript.configurations.getByName("classpath")
|
||||||
val subpluginClasspaths = hashMapOf<KotlinGradleSubplugin, List<String>>()
|
val subpluginClasspaths = hashMapOf<KotlinGradleSubplugin, List<String>>()
|
||||||
|
|
||||||
for (subplugin in subplugins) {
|
for (subplugin in subplugins) {
|
||||||
val files = classpath.getDependencies()
|
val files = classpath.dependencies
|
||||||
.filter { subpluginDependencyNames.contains(it.getGroup() + ":" + it.getName()) }
|
.filter { subpluginDependencyNames.contains(it.group + ":" + it.name) }
|
||||||
.flatMap { classpath.files(it).map { it.getAbsolutePath() } }
|
.flatMap { classpath.files(it).map { it.absolutePath } }
|
||||||
subpluginClasspaths.put(subplugin, files)
|
subpluginClasspaths.put(subplugin, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +492,7 @@ class SubpluginEnvironment(
|
|||||||
val args = subplugin.getExtraArguments(project, compileTask)
|
val args = subplugin.getExtraArguments(project, compileTask)
|
||||||
|
|
||||||
with (subplugin) {
|
with (subplugin) {
|
||||||
project.getLogger().kotlinDebug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.")
|
project.logger.kotlinDebug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val subpluginClasspath = subpluginClasspaths[subplugin]
|
val subpluginClasspath = subpluginClasspaths[subplugin]
|
||||||
@@ -513,16 +513,16 @@ class SubpluginEnvironment(
|
|||||||
|
|
||||||
open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInternal) {
|
open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInternal) {
|
||||||
public fun resolveDependencies(vararg coordinates: String): Collection<File> {
|
public fun resolveDependencies(vararg coordinates: String): Collection<File> {
|
||||||
val dependencyHandler: DependencyHandler = scriptHandler.getDependencies()
|
val dependencyHandler: DependencyHandler = scriptHandler.dependencies
|
||||||
val configurationsContainer: ConfigurationContainer = scriptHandler.getConfigurations()
|
val configurationsContainer: ConfigurationContainer = scriptHandler.configurations
|
||||||
|
|
||||||
val deps = coordinates.map { dependencyHandler.create(it) }
|
val deps = coordinates.map { dependencyHandler.create(it) }
|
||||||
val configuration = configurationsContainer.detachedConfiguration(*deps.toTypedArray())
|
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 kotlinPluginArtifactCoordinates(artifact: String): String = "org.jetbrains.kotlin:${artifact}:${kotlinPluginVersion()}"
|
||||||
public fun kotlinJsLibraryCoordinates(): String = kotlinPluginArtifactCoordinates("kotlin-js-library")
|
public fun kotlinJsLibraryCoordinates(): String = kotlinPluginArtifactCoordinates("kotlin-js-library")
|
||||||
|
|
||||||
@@ -537,10 +537,10 @@ fun AbstractCompile.storeKaptAnnotationsFile(kapt: AnnotationProcessingManager)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, File> {
|
private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, File> {
|
||||||
val aptOutputDir = File(getBuildDir(), "generated/source/kapt")
|
val aptOutputDir = File(buildDir, "generated/source/kapt")
|
||||||
val aptOutputDirForVariant = File(aptOutputDir, sourceSetName)
|
val aptOutputDirForVariant = File(aptOutputDir, sourceSetName)
|
||||||
|
|
||||||
val aptWorkingDir = File(getBuildDir(), "tmp/kapt")
|
val aptWorkingDir = File(buildDir, "tmp/kapt")
|
||||||
val aptWorkingDirForVariant = File(aptWorkingDir, sourceSetName)
|
val aptWorkingDirForVariant = File(aptWorkingDir, sourceSetName)
|
||||||
|
|
||||||
return aptOutputDirForVariant to aptWorkingDirForVariant
|
return aptOutputDirForVariant to aptWorkingDirForVariant
|
||||||
@@ -549,21 +549,21 @@ private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, Fi
|
|||||||
private fun Project.createAptConfiguration(sourceSetName: String, kotlinAnnotationProcessingDep: String): Configuration {
|
private fun Project.createAptConfiguration(sourceSetName: String, kotlinAnnotationProcessingDep: String): Configuration {
|
||||||
val aptConfigurationName = if (sourceSetName != "main") "kapt${sourceSetName.capitalize()}" else "kapt"
|
val aptConfigurationName = if (sourceSetName != "main") "kapt${sourceSetName.capitalize()}" else "kapt"
|
||||||
|
|
||||||
val aptConfiguration = getConfigurations().create(aptConfigurationName)
|
val aptConfiguration = configurations.create(aptConfigurationName)
|
||||||
aptConfiguration.getDependencies().add(getDependencies().create(kotlinAnnotationProcessingDep))
|
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
|
||||||
|
|
||||||
return aptConfiguration
|
return aptConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.createKaptExtension() {
|
private fun Project.createKaptExtension() {
|
||||||
getExtensions().create("kapt", KaptExtension::class.java)
|
extensions.create("kapt", KaptExtension::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
//copied from BasePlugin.getLocalVersion
|
//copied from BasePlugin.getLocalVersion
|
||||||
private fun loadAndroidPluginVersion(): String? {
|
private fun loadAndroidPluginVersion(): String? {
|
||||||
try {
|
try {
|
||||||
val clazz = BasePlugin::class.java
|
val clazz = BasePlugin::class.java
|
||||||
val className = clazz.getSimpleName() + ".class"
|
val className = clazz.simpleName + ".class"
|
||||||
val classPath = clazz.getResource(className).toString()
|
val classPath = clazz.getResource(className).toString()
|
||||||
if (!classPath.startsWith("jar")) {
|
if (!classPath.startsWith("jar")) {
|
||||||
// Class not from JAR, unlikely
|
// Class not from JAR, unlikely
|
||||||
@@ -571,12 +571,12 @@ private fun loadAndroidPluginVersion(): String? {
|
|||||||
}
|
}
|
||||||
val manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
|
val manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
|
||||||
|
|
||||||
val jarConnection = URL(manifestPath).openConnection();
|
val jarConnection = URL(manifestPath).openConnection()
|
||||||
jarConnection.setUseCaches(false);
|
jarConnection.useCaches = false
|
||||||
val jarInputStream = jarConnection.getInputStream();
|
val jarInputStream = jarConnection.inputStream
|
||||||
val attr = Manifest(jarInputStream).getMainAttributes();
|
val attr = Manifest(jarInputStream).mainAttributes
|
||||||
jarInputStream.close();
|
jarInputStream.close()
|
||||||
return attr.getValue("Plugin-Version");
|
return attr.getValue("Plugin-Version")
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -33,12 +33,12 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val kotlinPluginVersion = loadKotlinVersionFromResource(log)
|
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)
|
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<Project>
|
protected abstract fun getPlugin(pluginClassLoader: ClassLoader, scriptHandler: ScriptHandler): Plugin<Project>
|
||||||
@@ -46,16 +46,16 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
|||||||
private fun findSourceBuildScript(project: Project): ScriptHandler? {
|
private fun findSourceBuildScript(project: Project): ScriptHandler? {
|
||||||
log.kotlinDebug("Looking for proper script handler")
|
log.kotlinDebug("Looking for proper script handler")
|
||||||
var curProject = project
|
var curProject = project
|
||||||
while (curProject != curProject.getParent()) {
|
while (curProject != curProject.parent) {
|
||||||
log.kotlinDebug("Looking in project $project")
|
log.kotlinDebug("Looking in project $project")
|
||||||
val scriptHandler = curProject.getBuildscript()
|
val scriptHandler = curProject.buildscript
|
||||||
val found = scriptHandler.getConfigurations().findByName("classpath")?.firstOrNull { it.name.contains("kotlin-gradle-plugin") } != null
|
val found = scriptHandler.configurations.findByName("classpath")?.firstOrNull { it.name.contains("kotlin-gradle-plugin") } != null
|
||||||
if (found) {
|
if (found) {
|
||||||
log.kotlinDebug("Found! returning...")
|
log.kotlinDebug("Found! returning...")
|
||||||
return scriptHandler
|
return scriptHandler
|
||||||
}
|
}
|
||||||
log.kotlinDebug("not found, switching to parent")
|
log.kotlinDebug("not found, switching to parent")
|
||||||
curProject = curProject.getParent() ?: break
|
curProject = curProject.parent ?: break
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -15,8 +15,8 @@ public class ThreadTracker {
|
|||||||
public fun checkThreadLeak(gradle: Gradle?) {
|
public fun checkThreadLeak(gradle: Gradle?) {
|
||||||
try {
|
try {
|
||||||
val testThreads = gradle != null &&
|
val testThreads = gradle != null &&
|
||||||
gradle.getRootProject().hasProperty("kotlin.gradle.test") &&
|
gradle.rootProject.hasProperty("kotlin.gradle.test") &&
|
||||||
!gradle.getRootProject().hasProperty("kotlin.gradle.noThreadTest")
|
!gradle.rootProject.hasProperty("kotlin.gradle.noThreadTest")
|
||||||
|
|
||||||
Thread.sleep(if (testThreads) 200L else 50L)
|
Thread.sleep(if (testThreads) 200L else 50L)
|
||||||
|
|
||||||
@@ -26,10 +26,10 @@ public class ThreadTracker {
|
|||||||
for (thread in after) {
|
for (thread in after) {
|
||||||
if (thread == Thread.currentThread()) continue
|
if (thread == Thread.currentThread()) continue
|
||||||
|
|
||||||
val name = thread.getName()
|
val name = thread.name
|
||||||
|
|
||||||
if (testThreads) {
|
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 {
|
else {
|
||||||
log.info("Thread leaked: $thread: $name")
|
log.info("Thread leaked: $thread: $name")
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ internal fun Any.loadKotlinVersionFromResource(log: Logger): String {
|
|||||||
log.kotlinDebug("Loading version information")
|
log.kotlinDebug("Loading version information")
|
||||||
val props = Properties()
|
val props = Properties()
|
||||||
val propFileName = "project.properties"
|
val propFileName = "project.properties"
|
||||||
val inputStream = javaClass.getClassLoader()!!.getResourceAsStream(propFileName)
|
val inputStream = javaClass.classLoader!!.getResourceAsStream(propFileName)
|
||||||
|
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
throw FileNotFoundException("property file '" + propFileName + "' not found in the classpath")
|
throw FileNotFoundException("property file '" + propFileName + "' not found in the classpath")
|
||||||
|
|||||||
+2
-2
@@ -24,10 +24,10 @@ public open class KotlinTasksProvider(val tasksLoader: ClassLoader) {
|
|||||||
|
|
||||||
|
|
||||||
public fun createKotlinJVMTask(project: Project, name: String): AbstractCompile {
|
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 {
|
public fun createKotlinJSTask(project: Project, name: String): AbstractCompile {
|
||||||
return project.getTasks().create(name, kotlinJSCompileTaskClass)
|
return project.tasks.create(name, kotlinJSCompileTaskClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -122,7 +122,7 @@ abstract class BaseGradleIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.createBuildCommand(params: Array<out String>, options: BuildOptions): List<String> {
|
private fun Project.createBuildCommand(params: Array<out String>, options: BuildOptions): List<String> {
|
||||||
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
|
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").absolutePath
|
||||||
val tailParameters = params.asList() +
|
val tailParameters = params.asList() +
|
||||||
listOf( pathToKotlinPlugin,
|
listOf( pathToKotlinPlugin,
|
||||||
if (options.withDaemon) "--daemon" else "--no-daemon",
|
if (options.withDaemon) "--daemon" else "--no-daemon",
|
||||||
@@ -159,9 +159,9 @@ abstract class BaseGradleIT {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
val stdout = process.getInputStream()!!.readFully()
|
val stdout = process.inputStream!!.readFully()
|
||||||
System.out.println(stdout)
|
System.out.println(stdout)
|
||||||
val stderr = process.getErrorStream()!!.readFully()
|
val stderr = process.errorStream!!.readFully()
|
||||||
System.err.println(stderr)
|
System.err.println(stderr)
|
||||||
|
|
||||||
val result = process.waitFor()
|
val result = process.waitFor()
|
||||||
@@ -169,9 +169,9 @@ abstract class BaseGradleIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun copyRecursively(source: File, target: File) {
|
fun copyRecursively(source: File, target: File) {
|
||||||
assertTrue(target.isDirectory())
|
assertTrue(target.isDirectory)
|
||||||
val targetFile = File(target, source.getName())
|
val targetFile = File(target, source.name)
|
||||||
if (source.isDirectory()) {
|
if (source.isDirectory) {
|
||||||
targetFile.mkdir()
|
targetFile.mkdir()
|
||||||
source.listFiles()?.forEach { copyRecursively(it, targetFile) }
|
source.listFiles()?.forEach { copyRecursively(it, targetFile) }
|
||||||
} else {
|
} else {
|
||||||
@@ -180,13 +180,13 @@ abstract class BaseGradleIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun copyDirRecursively(source: File, target: File) {
|
fun copyDirRecursively(source: File, target: File) {
|
||||||
assertTrue(source.isDirectory())
|
assertTrue(source.isDirectory)
|
||||||
assertTrue(target.isDirectory())
|
assertTrue(target.isDirectory)
|
||||||
source.listFiles()?.forEach { copyRecursively(it, target) }
|
source.listFiles()?.forEach { copyRecursively(it, target) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteRecursively(f: File): Unit {
|
fun deleteRecursively(f: File): Unit {
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory) {
|
||||||
f.listFiles()?.forEach { deleteRecursively(it) }
|
f.listFiles()?.forEach { deleteRecursively(it) }
|
||||||
val fileList = f.listFiles()
|
val fileList = f.listFiles()
|
||||||
if (fileList != null) {
|
if (fileList != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user