Avoid exception when getting relative path

#KT-14056 fixed Target versions 1.0.5
This commit is contained in:
Alexey Tsvetkov
2016-09-28 20:53:49 +03:00
parent d293138c28
commit a474d75fe2
@@ -182,11 +182,12 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
} }
override fun callCompiler(args: K2JVMCompilerArguments, sources: List<File>, isIncrementalRequested: Boolean, modified: List<File>, removed: List<File>) { override fun callCompiler(args: K2JVMCompilerArguments, sources: List<File>, isIncrementalRequested: Boolean, modified: List<File>, removed: List<File>) {
fun projectRelativePath(file: File) = fun relativePathOrCanonical(file: File): String =
file.toRelativeString(project.rootProject.projectDir) file.relativeToOrNull(project.rootProject.projectDir)?.path
?: file.canonicalPath
fun filesToString(files: Iterable<File>) = fun filesToString(files: Iterable<File>) =
"[" + files.map(::projectRelativePath).sorted().joinToString(separator = ", \n") + "]" "[" + files.map(::relativePathOrCanonical).sorted().joinToString(separator = ", \n") + "]"
val targetType = "java-production" val targetType = "java-production"
val moduleName = args.moduleName val moduleName = args.moduleName
@@ -280,13 +281,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
lookupSymbols.addAll(classpathChanges.lookupSymbols) lookupSymbols.addAll(classpathChanges.lookupSymbols)
if (lookupSymbols.any()) { if (lookupSymbols.any()) {
val dirtyFilesFromLookups = mapLookupSymbolsToFiles(caches.lookupCache, lookupSymbols, logAction, ::projectRelativePath) val dirtyFilesFromLookups = mapLookupSymbolsToFiles(caches.lookupCache, lookupSymbols, logAction, ::relativePathOrCanonical)
dirtyFiles.addAll(dirtyFilesFromLookups) dirtyFiles.addAll(dirtyFilesFromLookups)
} }
val dirtyClassesFqNames = classpathChanges.fqNames.flatMap { withSubtypes(it, listOf(caches.incrementalCache)) } val dirtyClassesFqNames = classpathChanges.fqNames.flatMap { withSubtypes(it, listOf(caches.incrementalCache)) }
if (dirtyClassesFqNames.any()) { if (dirtyClassesFqNames.any()) {
val dirtyFilesFromFqNames = mapClassesFqNamesToFiles(listOf(caches.incrementalCache), dirtyClassesFqNames, logAction, ::projectRelativePath) val dirtyFilesFromFqNames = mapClassesFqNamesToFiles(listOf(caches.incrementalCache), dirtyClassesFqNames, logAction, ::relativePathOrCanonical)
dirtyFiles.addAll(dirtyFilesFromFqNames) dirtyFiles.addAll(dirtyFilesFromFqNames)
} }
@@ -362,11 +363,11 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
// can be empty if only removed sources are present // can be empty if only removed sources are present
if (sourcesToCompile.isNotEmpty()) { if (sourcesToCompile.isNotEmpty()) {
logger.kotlinInfo("compile iteration: ${sourcesToCompile.joinToString(transform = ::projectRelativePath)}") logger.kotlinInfo("compile iteration: ${sourcesToCompile.joinToString(transform = ::relativePathOrCanonical)}")
} }
val (existingSource, nonExistingSource) = sourcesToCompile.partition { it.isFile } val (existingSource, nonExistingSource) = sourcesToCompile.partition { it.isFile }
assert(nonExistingSource.isEmpty()) { "Trying to compile removed files: ${nonExistingSource.map(::projectRelativePath)}" } assert(nonExistingSource.isEmpty()) { "Trying to compile removed files: ${nonExistingSource.map(::relativePathOrCanonical)}" }
val text = existingSource.map { it.canonicalPath }.joinToString(separator = System.getProperty("line.separator")) val text = existingSource.map { it.canonicalPath }.joinToString(separator = System.getProperty("line.separator"))
dirtySourcesSinceLastTimeFile.writeText(text) dirtySourcesSinceLastTimeFile.writeText(text)
@@ -407,13 +408,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
sources.toSet() sources.toSet()
} }
is ChangesEither.Known -> { is ChangesEither.Known -> {
mapLookupSymbolsToFiles(caches.lookupCache, generatedJavaFilesChanges.lookupSymbols, logAction, ::projectRelativePath, excludes = sourcesToCompile) mapLookupSymbolsToFiles(caches.lookupCache, generatedJavaFilesChanges.lookupSymbols, logAction, ::relativePathOrCanonical, excludes = sourcesToCompile)
} }
else -> throw IllegalStateException("Unknown ChangesEither implementation: $generatedJavaFiles") else -> throw IllegalStateException("Unknown ChangesEither implementation: $generatedJavaFiles")
} }
sourcesToCompile = dirtyKotlinFilesFromJava + sourcesToCompile = dirtyKotlinFilesFromJava +
mapLookupSymbolsToFiles(caches.lookupCache, dirtyLookupSymbols, logAction, ::projectRelativePath, excludes = sourcesToCompile) + mapLookupSymbolsToFiles(caches.lookupCache, dirtyLookupSymbols, logAction, ::relativePathOrCanonical, excludes = sourcesToCompile) +
mapClassesFqNamesToFiles(listOf(caches.incrementalCache), dirtyClassFqNames, logAction, ::projectRelativePath, excludes = sourcesToCompile) mapClassesFqNamesToFiles(listOf(caches.incrementalCache), dirtyClassFqNames, logAction, ::relativePathOrCanonical, excludes = sourcesToCompile)
buildDirtyLookupSymbols.addAll(dirtyLookupSymbols) buildDirtyLookupSymbols.addAll(dirtyLookupSymbols)
buildDirtyFqNames.addAll(dirtyClassFqNames) buildDirtyFqNames.addAll(dirtyClassFqNames)