Last active
August 11, 2023 23:25
-
-
Save gamerson/05eed3759685bd08ead57fe619f0abe8 to your computer and use it in GitHub Desktop.
Script to print info for all plugins applied to a given project
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
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()}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bah! I need that to work! I'll try tot update it.