Skip to content

Instantly share code, notes, and snippets.

@JonathanLalou
Created June 6, 2017 04:18
Show Gist options
  • Save JonathanLalou/92ef1ee8c971d6fc3999f4b6af2e191c to your computer and use it in GitHub Desktop.
Save JonathanLalou/92ef1ee8c971d6fc3999f4b6af2e191c to your computer and use it in GitHub Desktop.
that no XHTML file misses id in <p:XYZ> or <b:XYZ> tags
/**
* Checks that no XHTML file misses id in <p:XYZ> or <b:XYZ> tags
* Limitations:
* <ul>
* <li>ignores some tags such as b:row, p:ajax, etc.</li>
* <li>quick and dirty</li>
* </ul>
*/
@Test
void 'check no missing id in XHTML component tags'() {
def errors = []
new File('../src/main/webapp/').traverse(type: FileType.FILES) {
file ->
if (!file.name.endsWith(".xhtml")) {
return
}
println "File Path: " + file.name
String fileContents = file.text
def tags = fileContents.findAll("<p:(.)*>")
tags.addAll(fileContents.findAll("<b:(.)*>"))
for (entry in tags) {
if (
entry.contains("id=\"")
|| entry.startsWith("<p:rowEditor")
|| entry.startsWith("<p:row")
|| entry.startsWith("<p:column")
|| entry.startsWith("<p:ajax")
|| entry.startsWith("<b:row")
|| entry.startsWith("<b:column")
|| entry.startsWith("<b:iconAwesome")
|| entry.startsWith("<b:icon")
) {
continue
}
errors.add(file.path + " " + entry)
}
}
if (!errors.isEmpty()) {
errors.each {
System.err.println("ERROR $it")
}
fail(errors.size() + " missing ids")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment