Skip to content

Commit

Permalink
Do not print stacktraces for warnings, just for debug messages
Browse files Browse the repository at this point in the history
Shorten messages of causes to 200 chars max.

Fixes issue jaredsburrows#229
  • Loading branch information
Thomas Keller committed Jul 11, 2023
1 parent 01569a0 commit 912c9a1
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final
try {
configuration.isCanBeResolved = true
} catch (e: Exception) {
logger.warn("Cannot resolve configuration ${configuration.name}", e)
logger.warn("Cannot resolve configuration ${configuration.name}: ${e.shortMessage()}")
logger.debug("Cannot resolve configuration ${configuration.name}", e)
}
}
}
Expand Down Expand Up @@ -226,7 +227,7 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final
// Search for licenses
var licenses = findLicenses(mavenReader, pomFile, configurations, dependencies)
if (licenses.isEmpty()) {
logger.warn("$name dependency does not have a license.")
logger.warn("Dependency '${artifact.name}' does not have a license.")
licenses = mutableListOf()
}

Expand Down Expand Up @@ -271,7 +272,8 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final
else -> resolvedArtifacts += resolvedDependency.allModuleArtifacts
}
} catch (e: Exception) {
logger.warn("Failed to process ${resolvedDependency.name}", e)
logger.warn("Failed to process '${resolvedDependency.name}': ${e.shortMessage()}")
logger.debug("Failed to process '${resolvedDependency.name}'", e)
}
}
return resolvedArtifacts
Expand Down Expand Up @@ -446,7 +448,8 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final
try {
uri = URL(this).toURI()
} catch (e: Exception) {
logger.warn("$this dependency has an invalid license URL; skipping license", e)
logger.warn("Dependency has an invalid license URL '$this': ${e.shortMessage()}")
logger.debug("Dependency has an invalid license URL '$this'", e)
}
return uri != null
}
Expand Down Expand Up @@ -489,10 +492,15 @@ internal open class LicenseReportTask : DefaultTask() { // tasks can't be final

private fun File?.isNullOrEmpty(): Boolean = this == null || this.length() == 0L

private fun Exception.shortMessage(): String = with(message ?: "<no message>") {
if (length > MAX_EXCEPTION_MESSAGE_LENGTH) substring(0, MAX_EXCEPTION_MESSAGE_LENGTH) + "... (see --debug for complete message)" else this
}

private companion object {
private const val ANDROID_SUPPORT_GROUP_ID = "com.android.support"
private const val APACHE_LICENSE_NAME = "The Apache Software License"
private const val APACHE_LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.txt"
private const val OPEN_SOURCE_LICENSES = "open_source_licenses"
private const val MAX_EXCEPTION_MESSAGE_LENGTH = 200
}
}

0 comments on commit 912c9a1

Please sign in to comment.