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() {
|
||||
|
||||
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<out TypeElement>?, 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()")
|
||||
|
||||
+2
-2
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public inline fun <T> ReentrantReadWriteLock.read(action: () -> T): T {
|
||||
public inline fun <T> 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()
|
||||
|
||||
@@ -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<FileInputStream, Long> {
|
||||
@@ -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()) {
|
||||
|
||||
@@ -8,8 +8,8 @@ class C()
|
||||
|
||||
class JavaClassTest() : TestCase() {
|
||||
fun testMe () {
|
||||
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.getName())
|
||||
assertEquals("java.util.ArrayList", ArrayList::class.java.getName())
|
||||
assertEquals("testjc.C", C::class.java.getName())
|
||||
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.name)
|
||||
assertEquals("java.util.ArrayList", ArrayList::class.java.name)
|
||||
assertEquals("testjc.C", C::class.java.name)
|
||||
}
|
||||
}
|
||||
@@ -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<String>()
|
||||
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<String>()
|
||||
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<File>()
|
||||
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<File>()
|
||||
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<File>()
|
||||
for (file in basedir.walkTopDown()) {
|
||||
if (file.name == ".git") {
|
||||
found.add(file.getParentFile())
|
||||
found.add(file.parentFile)
|
||||
}
|
||||
}
|
||||
assertEquals(3, found.size)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -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<String> {
|
||||
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<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||
@@ -127,13 +127,13 @@ public abstract class AnnotationProcessorWrapper(
|
||||
}
|
||||
|
||||
override fun getSupportedOptions(): MutableSet<String> {
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -17,18 +17,18 @@ internal class RoundEnvironmentWrapper(
|
||||
) : RoundEnvironment {
|
||||
|
||||
override fun getRootElements(): MutableSet<out Element>? {
|
||||
return parent.getRootElements()
|
||||
return parent.rootElements
|
||||
}
|
||||
|
||||
override fun getElementsAnnotatedWith(a: TypeElement): MutableSet<out Element>? {
|
||||
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<out Annotation>): MutableSet<out Element>? {
|
||||
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<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> {
|
||||
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<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) {
|
||||
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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+2
-2
@@ -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()
|
||||
|
||||
+31
-31
@@ -41,18 +41,18 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : 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<T : CommonCompilerArguments>() : AbstractCo
|
||||
private fun getKotlinSources(): List<File> = (getSource() as Iterable<File>).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<File>) {
|
||||
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<T : CommonCompilerArguments>() : 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<K2JVMCompilerArguments
|
||||
|
||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||
// show kotlin compiler where to look for java source files
|
||||
args.freeArgs = (args.freeArgs + getJavaSourceRoots().map { it.getAbsolutePath() }).toSet().toList()
|
||||
getLogger().kotlinDebug("args.freeArgs = ${args.freeArgs}")
|
||||
args.freeArgs = (args.freeArgs + getJavaSourceRoots().map { it.absolutePath }).toSet().toList()
|
||||
logger.kotlinDebug("args.freeArgs = ${args.freeArgs}")
|
||||
|
||||
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
||||
args.classpath = getClasspath().filter({ it != null && it.exists() }).joinToString(File.pathSeparator)
|
||||
getLogger().kotlinDebug("args.classpath = ${args.classpath}")
|
||||
args.classpath = classpath.filter({ it != null && it.exists() }).joinToString(File.pathSeparator)
|
||||
logger.kotlinDebug("args.classpath = ${args.classpath}")
|
||||
}
|
||||
|
||||
args.destination = if (StringUtils.isEmpty(kotlinOptions.destination)) {
|
||||
kotlinDestinationDir?.getPath()
|
||||
kotlinDestinationDir?.path
|
||||
} else {
|
||||
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()
|
||||
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 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<K2JVMCompilerArguments
|
||||
addFriendPathForTestTask(it)
|
||||
}
|
||||
|
||||
getLogger().kotlinDebug("args.moduleName = ${args.moduleName}")
|
||||
logger.kotlinDebug("args.moduleName = ${args.moduleName}")
|
||||
}
|
||||
|
||||
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
||||
val kaptAnnotationsFile = extraProperties.getOrNull<File>("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<File>("kaptStubsDir")
|
||||
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")
|
||||
@@ -191,12 +191,12 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
private fun File.isJavaFile() = extension.equals(JavaFileType.INSTANCE.getDefaultExtension(), ignoreCase = true)
|
||||
|
||||
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
|
||||
val outputDirFile = File(args.destination!!)
|
||||
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? {
|
||||
for (source in srcDirsSources) {
|
||||
if (source is SourceDirectorySet) {
|
||||
for (root in source.getSrcDirs()) {
|
||||
for (root in source.srcDirs) {
|
||||
if (FileUtil.isAncestor(root, file, false)) {
|
||||
return root
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
||||
}
|
||||
|
||||
public fun addLibraryFiles(vararg fs: File) {
|
||||
val strs = fs.map { it.getPath() }.toTypedArray()
|
||||
val strs = fs.map { it.path }.toTypedArray()
|
||||
addLibraryFiles(*strs)
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
||||
get() = kotlinOptions.sourceMap
|
||||
|
||||
init {
|
||||
getOutputs().file(MethodClosure(this, "getOutputFile"))
|
||||
outputs.file(MethodClosure(this, "getOutputFile"))
|
||||
}
|
||||
|
||||
override fun populateTargetSpecificArgs(args: K2JSCompilerArguments) {
|
||||
@@ -286,16 +286,16 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
||||
args.kjsm = kotlinOptions.kjsm
|
||||
|
||||
val kotlinJsLibsFromDependencies =
|
||||
getProject().getConfigurations().getByName("compile")
|
||||
project.configurations.getByName("compile")
|
||||
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
|
||||
.map { it.getAbsolutePath() }
|
||||
.map { it.absolutePath }
|
||||
|
||||
args.libraryFiles = kotlinOptions.libraryFiles + kotlinJsLibsFromDependencies
|
||||
args.target = kotlinOptions.target
|
||||
args.sourceMap = kotlinOptions.sourceMap
|
||||
|
||||
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
|
||||
@@ -305,8 +305,8 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
||||
}
|
||||
}
|
||||
|
||||
getLogger().debug("${getName()} set libraryFiles to ${args.libraryFiles.joinToString(",")}")
|
||||
getLogger().debug("${getName()} set outputFile to ${args.outputFile}")
|
||||
logger.debug("$name set libraryFiles to ${args.libraryFiles.joinToString(",")}")
|
||||
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")
|
||||
|
||||
val stubsDir = File(getBuildDir(), "tmp/kapt/$variantName/classFileStubs")
|
||||
val stubsDir = File(buildDir, "tmp/kapt/$variantName/classFileStubs")
|
||||
kotlinTask.extensions.extraProperties.set("kaptStubsDir", stubsDir)
|
||||
|
||||
javaTask.doFirst {
|
||||
@@ -217,7 +217,7 @@ public class AnnotationProcessingManager(
|
||||
getProcessorStubClassName(processorFqName),
|
||||
taskQualifier) as File
|
||||
|
||||
project.getLogger().kotlinDebug("kapt: Wrapper for $processorFqName generated: $wrapperFile")
|
||||
project.logger.kotlinDebug("kapt: Wrapper for $processorFqName generated: $wrapperFile")
|
||||
}
|
||||
|
||||
val annotationProcessorWrapperFqNames = processorFqNames
|
||||
@@ -251,7 +251,7 @@ public class AnnotationProcessingManager(
|
||||
javaTask.addCompilerArgument("-s") { prevValue ->
|
||||
if (prevValue != null)
|
||||
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)
|
||||
|
||||
init {
|
||||
kotlin.getFilter()?.include("**/*.java", "**/*.kt")
|
||||
kotlin.filter?.include("**/*.java", "**/*.kt")
|
||||
}
|
||||
|
||||
override fun getKotlin(): SourceDirectorySet {
|
||||
|
||||
+2
-2
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
+79
-79
@@ -50,13 +50,13 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
|
||||
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<T : AbstractCompile>(
|
||||
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<T : AbstractCompile>(
|
||||
|
||||
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<String>(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> { sourceSet ->
|
||||
javaPluginConvention.sourceSets?.all(Action<SourceSet> { 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<AndroidSourceSet> { sourceSet ->
|
||||
ext.sourceSets.all(Action<AndroidSourceSet> { 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<String, Configuration>
|
||||
) {
|
||||
val logger = project.getLogger()
|
||||
val logger = project.logger
|
||||
val kotlinOptions = getExtension<Any?>(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<File>) {
|
||||
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<File>()
|
||||
|
||||
// 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<KotlinSourceSet>(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 <T> 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<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>>()
|
||||
|
||||
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<File> {
|
||||
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<File, File> {
|
||||
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<File, Fi
|
||||
private fun Project.createAptConfiguration(sourceSetName: String, kotlinAnnotationProcessingDep: String): Configuration {
|
||||
val aptConfigurationName = if (sourceSetName != "main") "kapt${sourceSetName.capitalize()}" else "kapt"
|
||||
|
||||
val aptConfiguration = getConfigurations().create(aptConfigurationName)
|
||||
aptConfiguration.getDependencies().add(getDependencies().create(kotlinAnnotationProcessingDep))
|
||||
val aptConfiguration = configurations.create(aptConfigurationName)
|
||||
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
|
||||
|
||||
return aptConfiguration
|
||||
}
|
||||
|
||||
private fun Project.createKaptExtension() {
|
||||
getExtensions().create("kapt", KaptExtension::class.java)
|
||||
extensions.create("kapt", KaptExtension::class.java)
|
||||
}
|
||||
|
||||
//copied from BasePlugin.getLocalVersion
|
||||
private fun loadAndroidPluginVersion(): String? {
|
||||
try {
|
||||
val clazz = BasePlugin::class.java
|
||||
val className = clazz.getSimpleName() + ".class"
|
||||
val className = clazz.simpleName + ".class"
|
||||
val classPath = clazz.getResource(className).toString()
|
||||
if (!classPath.startsWith("jar")) {
|
||||
// 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 jarConnection = URL(manifestPath).openConnection();
|
||||
jarConnection.setUseCaches(false);
|
||||
val jarInputStream = jarConnection.getInputStream();
|
||||
val attr = Manifest(jarInputStream).getMainAttributes();
|
||||
jarInputStream.close();
|
||||
return attr.getValue("Plugin-Version");
|
||||
val jarConnection = URL(manifestPath).openConnection()
|
||||
jarConnection.useCaches = false
|
||||
val jarInputStream = jarConnection.inputStream
|
||||
val attr = Manifest(jarInputStream).mainAttributes
|
||||
jarInputStream.close()
|
||||
return attr.getValue("Plugin-Version")
|
||||
} catch (t: Throwable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+7
-7
@@ -33,12 +33,12 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
||||
}
|
||||
|
||||
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<Project>
|
||||
@@ -46,16 +46,16 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
|
||||
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
|
||||
}
|
||||
|
||||
+4
-4
@@ -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")
|
||||
|
||||
+1
-1
@@ -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")
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -122,7 +122,7 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
|
||||
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() +
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user