Skip to content

Instantly share code, notes, and snippets.

@h-mochizuki
Created November 7, 2019 01:46
Show Gist options
  • Save h-mochizuki/0b2c7caa48c7dd7be4aabf0af8f71a89 to your computer and use it in GitHub Desktop.
Save h-mochizuki/0b2c7caa48c7dd7be4aabf0af8f71a89 to your computer and use it in GitHub Desktop.
JBoss Enable Module Checker
apply from: "jboss-mocule-checker.gradle"
check {
deploymentStructure = "C:/path/to/jboss-deployment-structure.xml"
jbossHome = "C:/path/to/jboss-eap-7.2"
}
apply plugin: JBossModuleCheckPlugin
buildscript {
repositories { mavenCentral() }
dependencies {
classpath("org.gebish:geb-core:3.+") { exclude group: "org.codehaus.groovy" }
classpath "org.seleniumhq.selenium:selenium-chrome-driver:3.+"
classpath "io.github.bonigarcia:webdrivermanager:3.+"
}
}
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import geb.Browser
import geb.driver.CachingDriverFactory
import geb.navigator.Locator
import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
class JBossModuleCheckPluginConfiguration {
final String STATUS_URL = "https://access.redhat.com/articles/2158031"
final String status = "./status.json"
String jbossHome = "/jboss-eap-7.2"
String deploymentStructure = "./jboss-deployment-structure.xml"
}
class CheckUtil {
static List modules(File jbossDeploymentStructure) {
List modules = []
if (jbossDeploymentStructure?.isDirectory()) {
jbossDeploymentStructure.traverse(
type: groovy.io.FileType.FILES,
nameFilter: ~/.*\.xml/,
) { f ->
def xml = new XmlParser().parse(f)
modules << xml.depthFirst().findAll {
it.name().toString().endsWith('dependencies')
}.collect { it.depthFirst().findAll {
it.name().toString().endsWith('module')
}}.flatten().collect {
it.@name
}
modules << xml.depthFirst().findAll {
it.name().toString().endsWith('resources')
}.collect { it.depthFirst().findAll {
it.name().toString().endsWith('resource-root')
}}.flatten().collect {
it.@path
}
}
} else {
def xml = new XmlParser().parse(jbossDeploymentStructure)
modules << xml.depthFirst().findAll {
it.name().toString().endsWith('dependencies')
}.collect { it.depthFirst().findAll {
it.name().toString().endsWith('module')
}}.flatten().collect {
it.@name
}
modules << xml.depthFirst().findAll {
it.name().toString().endsWith('resources')
}.collect { it.depthFirst().findAll {
it.name().toString().endsWith('resource-root')
}}.flatten().collect {
it.@path
}
}
modules.flatten()
}
static Map loadJson(String path) {
File f = new File(path)
f.exists() ? new JsonSlurper().parseText(f.text) as Map : [:]
}
static void dumpJson(Map map, String path) {
def json = new JsonBuilder()
json(map)
new File(path).text = json.toString()
}
static File moduleXml(File moduleRoot, String moduleName) {
File module = null
moduleRoot.traverse(
type: groovy.io.FileType.FILES,
nameFilter: ~/.*module\.xml/,
) { mod ->
String path = mod.absolutePath.replaceAll('\\\\', '\\.')
if (path.contains(".${moduleName}.main.module.xml")) {
module = mod
groovy.io.FileVisitResult.TERMINATE
}
}
module
}
}
class JBossModuleCheckPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create('check', JBossModuleCheckPluginConfiguration);
project.task('check') {
doFirst { check(project) }
}
}
static def check(Project project) {
CachingDriverFactory.clearCacheAndQuitDriver()
WebDriverManager.chromedriver().setup()
Browser browser = new Browser()
def status = CheckUtil.loadJson(project.check.status)
if (!status) {
try {
browser.with {
driver = new ChromeDriver(new ChromeOptions())
go project.check.STATUS_URL
waitFor(message: "ステータスチェック画面が表示できません") {
title.contains("Included Modules")
}
status = $(".field-name-field-kcs-article-body").$("table").$("tbody").$("tr").collectEntries { tr ->
[ tr.children()[0].text(), tr.children()[1].text() ]
}
CheckUtil.dumpJson(status, project.check.status)
}
} catch (Exception e) {
e.printStackTrace()
throw new GradleException("処理に失敗しました", e)
} finally {
browser?.quit()
CachingDriverFactory.clearCacheAndQuitDriver()
}
}
CheckUtil.modules(new File(project.check.deploymentStructure))?.each {
dependsOn(project, status, it)
}
}
static void dependsOn(Project project, Map status, String module, int indentLevel = 0) {
String indent = "\t" * indentLevel
boolean unsupported = ['UNSUPPORTED', '------'].contains(status[module])
boolean dependsOnUnsupported = indentLevel > 0 && (!['PUBLIC', "PRIVATE"].contains(status[module]))
if (module.endsWith(".jar")) {
println "${indent}${module}"
} else {
println "${indent}${module}: ${status[module]?:'------'}"
}
if (unsupported || dependsOnUnsupported) {
def m = CheckUtil.moduleXml(new File("${project.check.jbossHome}/modules"), module)
if (m != null) CheckUtil.modules(m).each {
dependsOn(project, status, it, indentLevel + 1)
}
}
}
}
@h-mochizuki
Copy link
Author

gradle check

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