Skip to content

Instantly share code, notes, and snippets.

def retry(func, ex_type=Exception, limit=0, wait_ms=100, wait_increase_ratio=2, logger=None):
"""
Retry a function invocation until no exception occurs
:param func: function to invoke
:param ex_type: retry only if exception is subclass of this type
:param limit: maximum number of invocation attempts
:param wait_ms: initial wait time after each attempt in milliseconds.
:param wait_increase_ratio: increase wait period by multiplying this value after each attempt.
:param logger: if not None, retry attempts will be logged to this logging.logger
:return: result of first successful invocation
...
[INFO] The following files have been resolved:
[INFO] commons-cli:commons-cli:jar:1.4:compile
[INFO] io.grpc:grpc-netty-shaded:jar:1.25.0:compile
[INFO] org.jetbrains.kotlin:kotlin-test:jar:1.4.31:test
[INFO] com.google.api.grpc:proto-google-common-protos:jar:1.12.0:compile
[INFO] com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] com.squareup.moshi:moshi:jar:1.8.0:compile
[INFO] com.google.protobuf:protobuf-java:jar:3.10.0:compile
[INFO] junit:junit:jar:4.13.1:test
fun getLoadedPackageGroupVersions(detailed: Boolean = false, vararg excludePrefixes: String): String {
fun getProductDetails(packageGroup: List<Package>): String {
val samplePackage = packageGroup.first()
val prodTitle =
"\t${samplePackage.implementationTitle} " +
"v(${samplePackage.implementationVersion}) by ${samplePackage.implementationVendor}"
if (!detailed)
return prodTitle
val details = packageGroup.map { "\t\t" + it.name }.sorted().joinToString("\n")
57 JAR files below lib:
lib/annotations-13.0.jar
lib/byte-buddy-1.9.0.jar
lib/byte-buddy-agent-1.9.0.jar
lib/commons-cli-1.4.jar
lib/commons-codec-1.13.jar
lib/commons-csv-1.8.jar
lib/commons-lang3-3.9.jar
lib/commons-logging-1.2.jar
...
fun getJarVersions(jarFolder: String): String {
val jarFiles = File(jarFolder)
.listFiles { _, name -> name.toLowerCase().endsWith(".jar") }
?: emptyArray()
val text = jarFiles.map { "\t" + it }.sorted().joinToString("\n")
return "${jarFiles.size} JAR files below ${jarFolder}: \n${text}"
}
object App {
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
Versions of 123 loaded packages in 12 products:
Apache Commons CLI v(1.4) by The Apache Software Foundation
Apache Log4j API v(2.17.0) by The Apache Software Foundation
Apache Log4j Core v(2.17.0) by The Apache Software Foundation
JUnit v(4.13.1) by JUnit
Jackson-annotations v(2.12.3) by FasterXML
Jackson-core v(2.12.3) by FasterXML
Jackson-dataformat-YAML v(2.12.3) by FasterXML
hamcrest-core v(1.3) by hamcrest.org
jackson-databind v(2.12.3) by FasterXML
Versions of 123 loaded packages in 12 products:
Apache Commons CLI v(1.4) by The Apache Software Foundation
org.apache.commons.cli
Apache Log4j API v(2.17.0) by The Apache Software Foundation
org.apache.logging.log4j
org.apache.logging.log4j.internal
org.apache.logging.log4j.message
org.apache.logging.log4j.simple
org.apache.logging.log4j.spi
org.apache.logging.log4j.status
fun String.startsWithAny(vararg prefixes: String): Boolean {
return prefixes.any { this.startsWith(it) }
}
fun getLoadedPackageVersions(vararg excludePrefixes: String): String {
val packages = Package.getPackages()
val filteredPackages = packages.filterNot {
it.name.startsWithAny(*excludePrefixes)
}
val versionsText = filteredPackages
Versions of 123 loaded packages:
..
kotlin.text: kotlin-stdlib v(1.4.31-release-344 (1.4.31)) by JetBrains
kotlin: kotlin-stdlib v(1.4.31-release-344 (1.4.31)) by JetBrains
org.apache.commons.cli: Apache Commons CLI v(1.4) by The Apache Software Foundation
org.apache.logging.log4j.core.appender.db.jdbc: Apache Log4j Core v(2.17.0) by The Apache Software Foundation
org.apache.logging.log4j.core.appender.db: Apache Log4j Core v(2.17.0) by The Apache Software Foundation
org.apache.logging.log4j.core.appender.mom.jeromq: Apache Log4j Core v(2.17.0) by The Apache Software Foundation
org.apache.logging.log4j.core.appender.mom.kafka: Apache Log4j Core v(2.17.0) by The Apache Software Foundation
org.fusesource.jansi: jansi v(1.18) by FuseSource, Corp.