Gradle: debug message prefix added

This commit is contained in:
Natalia Ukhorskaya
2015-05-26 12:36:13 +03:00
parent cab2328b64
commit 0fbcfddf4a
5 changed files with 45 additions and 30 deletions
@@ -111,9 +111,11 @@ 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}")
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
args.classpath = getClasspath().filter({ it != null && it.exists() }).joinToString(File.pathSeparator)
getLogger().kotlinDebug("args.classpath = ${args.classpath}")
}
args.destination = if (StringUtils.isEmpty(kotlinOptions.destination)) {
@@ -121,9 +123,11 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
} else {
kotlinOptions.destination
}
getLogger().kotlinDebug("args.destination = ${args.destination}")
val extraProperties = getExtensions().getExtraProperties()
args.pluginClasspaths = extraProperties.get("compilerPluginClasspaths") as? Array<String>
getLogger().kotlinDebug("args.pluginClasspaths = ${args.pluginClasspaths.joinToString(File.pathSeparator)}")
val basePluginOptions = (extraProperties.get("compilerPluginArguments") as? Array<String>) ?: array()
val pluginOptions = arrayListOf(*basePluginOptions)
@@ -135,12 +139,14 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
}
args.pluginOptions = pluginOptions.toTypedArray()
getLogger().kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}")
val embeddedAnnotations = getAnnotations(getProject(), getLogger())
val userAnnotations = kotlinOptions.annotations?.split(File.pathSeparatorChar)?.toList() ?: emptyList()
val allAnnotations = if (kotlinOptions.noJdkAnnotations) userAnnotations else userAnnotations.plus(embeddedAnnotations.map { it.getPath() })
if (allAnnotations.isNotEmpty()) {
args.annotations = allAnnotations.join(File.pathSeparator)
getLogger().kotlinDebug("args.annotations = ${args.annotations}")
}
args.noStdlib = true
@@ -384,3 +390,7 @@ class GradleMessageCollector(val logger: Logger) : MessageCollector {
}
}
}
fun Logger.kotlinDebug(message: String) {
this.debug("[KOTLIN] $message")
}
@@ -28,7 +28,7 @@ class FinishBuildListener(var pluginClassLoader: ParentLastURLClassLoader?) : Bu
private var threadTracker: ThreadTracker? = ThreadTracker()
override fun buildFinished(result: BuildResult?) {
log.debug("Build finished listener")
log.kotlinDebug("Build finished listener")
stopZipFileCache()
stopLowMemoryWatcher()
@@ -47,7 +47,7 @@ class FinishBuildListener(var pluginClassLoader: ParentLastURLClassLoader?) : Bu
public fun removeThreadLocals() {
try {
log.debug("Remove ChildURLClassLoader thread locals")
log.kotlinDebug("Remove ChildURLClassLoader thread locals")
val thread = Thread.currentThread()
val threadLocalsField = javaClass<Thread>().getDeclaredField("threadLocals")
@@ -72,24 +72,24 @@ class FinishBuildListener(var pluginClassLoader: ParentLastURLClassLoader?) : Bu
}
}
log.debug("Removing ChildURLClassLoader thread locals finished successfully")
log.kotlinDebug("Removing ChildURLClassLoader thread locals finished successfully")
} catch (e: Throwable) {
log.debug("Exception during thread locals remove: " + e)
log.kotlinDebug("Exception during thread locals remove: " + e)
}
}
private fun stopZipFileCache() {
callVoidStaticMethod("com.intellij.openapi.util.io.ZipFileCache", "stopBackgroundThread")
log.debug("ZipFileCache finished successfully")
log.kotlinDebug("ZipFileCache finished successfully")
}
private fun stopLowMemoryWatcher() {
callVoidStaticMethod("com.intellij.openapi.util.LowMemoryWatcher", "stopAll")
log.debug("LowMemoryWatcher finished successfully")
log.kotlinDebug("LowMemoryWatcher finished successfully")
}
private fun stopJobScheduler() {
log.debug("Stop JobScheduler")
log.kotlinDebug("Stop JobScheduler")
val jobSchedulerClass = Class.forName("com.intellij.concurrency.JobScheduler", false, pluginClassLoader)
@@ -97,19 +97,19 @@ class FinishBuildListener(var pluginClassLoader: ParentLastURLClassLoader?) : Bu
val executorService = getSchedulerMethod.invoke(this) as ScheduledExecutorService
executorService.shutdown()
log.debug("JobScheduler stopped")
log.kotlinDebug("JobScheduler stopped")
}
private fun callVoidStaticMethod(classFqName: String, methodName: String) {
val shortName = classFqName.substring(classFqName.lastIndexOf('.') + 1)
log.debug("Looking for $shortName class")
log.kotlinDebug("Looking for $shortName class")
val lowMemoryWatcherClass = Class.forName(classFqName, false, pluginClassLoader)
log.debug("Looking for $methodName() method")
log.kotlinDebug("Looking for $methodName() method")
val shutdownMethod = lowMemoryWatcherClass.getMethod(methodName)
log.debug("Call $shortName.$methodName()")
log.kotlinDebug("Call $shortName.$methodName()")
shutdownMethod.invoke(null)
}
}
@@ -82,7 +82,7 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
open protected fun createKotlinSourceSet(): KotlinSourceSet? =
if (sourceSet is HasConvention) {
logger.debug("Creating KotlinSourceSet for source set ${sourceSet}")
logger.kotlinDebug("Creating KotlinSourceSet for source set ${sourceSet}")
val kotlinSourceSet = KotlinSourceSetImpl(sourceSet.getName(), project.getFileResolver())
sourceSet.getConvention().getPlugins().put(pluginName, kotlinSourceSet)
kotlinSourceSet
@@ -92,14 +92,14 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
open protected fun createKotlinDirSet(): SourceDirectorySet? {
val srcDir = project.file(sourceRootDir)
logger.debug("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.debug("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()) }
@@ -107,7 +107,7 @@ abstract class KotlinSourceSetProcessor<T : AbstractCompile>(
open protected fun createKotlinCompileTask(): T {
val name = sourceSet.getCompileTaskName(compileTaskNameSuffix)
logger.debug("Creating kotlin compile task $name with class $compilerClass")
logger.kotlinDebug("Creating kotlin compile task $name with class $compilerClass")
return project.getTasks().create(name, compilerClass)
}
@@ -329,7 +329,7 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
}))
but those methods were removed so commented as temporary hack*/
project.getLogger().debug("Created kotlin sourceDirectorySet at ${kotlinDirSet.getSrcDirs()}")
project.getLogger().kotlinDebug("Created kotlin sourceDirectorySet at ${kotlinDirSet.getSrcDirs()}")
}
})
@@ -363,7 +363,7 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
for (variantData in variantDataList) {
val variantDataName = variantData.getName()
logger.debug("Process variant [$variantDataName]")
logger.kotlinDebug("Process variant [$variantDataName]")
val javaTask = variantData.javaCompileTask
@@ -384,7 +384,7 @@ open class KotlinAndroidPlugin [Inject] (val scriptHandler: ScriptHandler, val t
fun SourceDirectorySet.addSourceDirectories(additionalSourceFiles: Collection<File>) {
for (dir in additionalSourceFiles) {
this.srcDir(dir)
logger.debug("Source directory ${dir.getAbsolutePath()} was added to kotlin source for $kotlinTaskName")
logger.kotlinDebug("Source directory ${dir.getAbsolutePath()} was added to kotlin source for $kotlinTaskName")
}
}
@@ -496,7 +496,7 @@ private class SubpluginEnvironment(
val args = subplugin.getExtraArguments(project, compileTask)
with (subplugin) {
logger.debug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.")
logger.kotlinDebug("Subplugin ${getPluginName()} (${getGroupName()}:${getArtifactName()}) loaded.")
}
val subpluginClasspath = subpluginClasspaths[subplugin]
@@ -10,6 +10,7 @@ import java.util.Properties
import java.io.FileNotFoundException
import org.gradle.api.initialization.dsl.ScriptHandler
import org.gradle.api.invocation.Gradle
import org.gradle.api.logging.Logger
import java.lang.reflect.Method
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
@@ -41,33 +42,33 @@ abstract class KotlinBasePluginWrapper: Plugin<Project> {
val dependencyHandler: DependencyHandler = sourceBuildScript.getDependencies()
val configurationsContainer: ConfigurationContainer = sourceBuildScript.getConfigurations()
log.debug("Creating configuration and dependency")
log.kotlinDebug("Creating configuration and dependency")
val kotlinPluginCoreCoordinates = "org.jetbrains.kotlin:kotlin-gradle-plugin-core:" + projectVersion
val dependency = dependencyHandler.create(kotlinPluginCoreCoordinates)
val configuration = configurationsContainer.detachedConfiguration(dependency)
log.debug("Resolving [" + kotlinPluginCoreCoordinates + "]")
log.kotlinDebug("Resolving [" + kotlinPluginCoreCoordinates + "]")
val kotlinPluginDependencies: List<URL> = configuration.getResolvedConfiguration().getFiles({ true })!!.map { it.toURI().toURL() }
log.debug("Resolved files: [" + kotlinPluginDependencies.toString() + "]")
log.debug("Load plugin in parent-last URL classloader")
log.kotlinDebug("Resolved files: [" + kotlinPluginDependencies.toString() + "]")
log.kotlinDebug("Load plugin in parent-last URL classloader")
val kotlinPluginClassloader = ParentLastURLClassLoader(kotlinPluginDependencies, this.javaClass.getClassLoader())
log.debug("Class loader created")
log.kotlinDebug("Class loader created")
return kotlinPluginClassloader
}
private fun findSourceBuildScript(project: Project): ScriptHandler? {
log.debug("Looking for proper script handler")
log.kotlinDebug("Looking for proper script handler")
var curProject = project
while (curProject != curProject.getParent()) {
log.debug("Looking in project $project")
log.kotlinDebug("Looking in project $project")
val scriptHandler = curProject.getBuildscript()
val found = scriptHandler.getConfigurations().findByName("classpath")?.firstOrNull { it.name.contains("kotlin-gradle-plugin") } != null
if (found) {
log.debug("Found! returning...")
log.kotlinDebug("Found! returning...")
return scriptHandler
}
log.debug("not found, switching to parent")
log.kotlinDebug("not found, switching to parent")
curProject = curProject.getParent()!!
}
return null
@@ -86,3 +87,7 @@ open class Kotlin2JsPluginWrapper : KotlinBasePluginWrapper() {
override fun getPlugin(pluginClassLoader: ParentLastURLClassLoader, scriptHandler: ScriptHandler) = Kotlin2JsPlugin(scriptHandler, KotlinTasksProvider(pluginClassLoader))
}
fun Logger.kotlinDebug(message: String) {
this.debug("[KOTLIN] $message")
}
@@ -21,7 +21,7 @@ import java.io.FileNotFoundException
import java.util.*
private fun Any.loadKotlinVersionFromResource(log: Logger): String {
log.debug("Loading version information")
log.kotlinDebug("Loading version information")
val props = Properties()
val propFileName = "project.properties"
val inputStream = javaClass.getClassLoader()!!.getResourceAsStream(propFileName)
@@ -33,6 +33,6 @@ private fun Any.loadKotlinVersionFromResource(log: Logger): String {
props.load(inputStream)
val projectVersion = props["project.version"] as String
log.debug("Found project version [$projectVersion]")
log.kotlinDebug("Found project version [$projectVersion]")
return projectVersion
}