Skip to content

Instantly share code, notes, and snippets.

@gamerson
Last active August 11, 2023 23:25
Show Gist options
  • Save gamerson/05eed3759685bd08ead57fe619f0abe8 to your computer and use it in GitHub Desktop.
Save gamerson/05eed3759685bd08ead57fe619f0abe8 to your computer and use it in GitHub Desktop.
Script to print info for all plugins applied to a given project
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
allprojects {
task pluginInfo
pluginInfo {
doLast {
def appliedClasses = []
def classesIds = [:]
Set classpath = []
plugins.each {
appliedClasses << it.class.name
it.class.classLoader.getURLs().each { classpath.add(it)}
def jarUrl = it.class.protectionDomain.codeSource.location
def pluginPath = Paths.get(jarUrl.toURI())
def pluginUri = URI.create("jar:" + pluginPath.toUri())
def jarFs
try {
jarFs = FileSystems.getFileSystem(pluginUri)
}
catch (Throwable t) {
}
if (jarFs == null) {
jarFs = FileSystems.newFileSystem(pluginUri, Collections.emptyMap())
}
def gradlePlugins = jarFs.getPath("/META-INF/gradle-plugins")
Files.walkFileTree(gradlePlugins, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
if (path.toString().endsWith(".properties")) {
Properties properties = new Properties()
properties.load(jarFs.provider.newInputStream(path))
String implClass = properties.get("implementation-class")
if (implClass != null) {
classesIds.put(implClass, path.fileName.toString().replaceAll(".properties\$",""))
}
}
return FileVisitResult.CONTINUE;
}
});
}
println "Plugin classpath..."
classpath.each { println it }
println "Applied ids..."
def appliedIds = classesIds.findAll { appliedClasses.contains(it.key) }
appliedIds.each { println "$it.value = $it.key" }
println "\nTotal plugins applied = ${appliedIds.size()}"
}
}
}
@lawrence-lee
Copy link

This doesnt work with Zulu jdk 11

@gamerson
Copy link
Author

Bah! I need that to work! I'll try tot update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment