-
-
Save drewbrokke/6ce2762f9ca3c71690cc98003bbcded5 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 | |
if (jarUrl == null) { | |
println "WARNING: no codeSource location found for class: " + it.class.name | |
return | |
} | |
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