-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PackageSearchApiPackageCache ins separate module
PackageSearchApiPackageCache tests classpath was poised by the IJ Gradle plugin. Moving it in a simple Kotlin/JVM module solved the issue.
- Loading branch information
Showing
28 changed files
with
21,092 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/utils/IntelliJLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.jetbrains.packagesearch.plugin.utils | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.Service.Level | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.jetbrains.packagesearch.plugin.FeatureFlags | ||
import com.jetbrains.packagesearch.plugin.core.PackageSearch | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
@Service(Level.APP) | ||
class IntelliJLogger : PluginLogger { | ||
|
||
private val logger: Logger = Logger.getInstance("#${PackageSearch.pluginId}") | ||
private val warned = AtomicBoolean(false) | ||
|
||
override fun logError(message: String, throwable: Throwable?) { | ||
logger.error(message, throwable) | ||
} | ||
|
||
override fun logError(contextName: String?, throwable: Throwable?, messageProvider: () -> String) { | ||
logError(buildMessageFrom(contextName, messageProvider), throwable) | ||
} | ||
|
||
override fun logWarn(message: String, throwable: Throwable?) { | ||
logger.warn(message, throwable) | ||
} | ||
|
||
override fun logWarn(contextName: String?, throwable: Throwable?, messageProvider: () -> String) { | ||
logWarn(buildMessageFrom(contextName, messageProvider), throwable) | ||
} | ||
|
||
override fun logInfo(message: String, throwable: Throwable?) { | ||
logger.info(message, throwable) | ||
} | ||
|
||
override fun logInfo(contextName: String?, throwable: Throwable?, messageProvider: () -> String) { | ||
logInfo(buildMessageFrom(contextName, messageProvider), throwable) | ||
} | ||
|
||
override fun logDebug(message: String, throwable: Throwable?) { | ||
if (!logger.isDebugEnabled) warnNotLoggable() | ||
logger.debug(message, throwable) | ||
} | ||
|
||
override fun logDebug(contextName: String?, throwable: Throwable?, message: String?) { | ||
logDebug(buildMessageFrom(contextName, message = message), throwable) | ||
} | ||
|
||
override fun logDebug(contextName: String?, throwable: Throwable?, messageProvider: () -> String) { | ||
logDebug(buildMessageFrom(contextName, messageProvider), throwable) | ||
} | ||
|
||
override fun logTrace(message: String) { | ||
if (!FeatureFlags.useDebugLogging || !logger.isTraceEnabled) warnNotLoggable() | ||
logger.trace(message) | ||
} | ||
|
||
override fun logTrace(throwable: Throwable) { | ||
if (!FeatureFlags.useDebugLogging || !logger.isTraceEnabled) warnNotLoggable() | ||
logger.trace(throwable) | ||
} | ||
|
||
override fun logTODO() { | ||
logWarn("This feature is not implemented yet") { | ||
"Stacktrace:\n" + Thread.currentThread().stackTrace.joinToString("\n") { | ||
"${it.className}.${it.methodName}(${it.fileName}:${it.lineNumber})" | ||
} | ||
} | ||
} | ||
|
||
private fun warnNotLoggable() { | ||
if (warned.getAndSet(true)) return | ||
logger.warn( | ||
""" | ||
|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|Debug logging not enabled. Make sure you have a line like this: | ||
| #${PackageSearch.pluginId}:trace | ||
|in your debug log settings (Help | Diagnostic Tools | Debug Log Settings) | ||
|then restart the IDE. | ||
|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|""".trimMargin() | ||
) | ||
} | ||
} | ||
|
||
fun buildMessageFrom( | ||
contextName: String?, | ||
messageProvider: (() -> String)? = null, | ||
message: String? = null, | ||
): String = buildString { | ||
if (!contextName.isNullOrBlank()) { | ||
append(contextName) | ||
append(' ') | ||
} | ||
if (isNotEmpty()) append("- ") | ||
messageProvider?.let { append(it()) } | ||
message?.let { append(it) } | ||
} |
Oops, something went wrong.