Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/kotlin/no/item/xp/plugin/GenerateCodePlugin.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.item.xp.plugin

import no.item.xp.plugin.phrases.GenerateI18nPhrasesTask
import no.item.xp.plugin.util.IGNORED_XML_FILE_NAMES
import no.item.xp.plugin.util.getTargetFile
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -14,7 +15,7 @@ abstract class GenerateCodePlugin : Plugin<Project> {
javaExt.sourceSets
.getAt("main")
.resources
.filter { it.extension == "xml" && it.name != "application.xml" && it.name != "styles.xml" }
.filter { it.extension == "xml" && it.name !in IGNORED_XML_FILE_NAMES }
.files

val targetDir = File(project.rootDir.absolutePath + File.separator + ".xp-codegen")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/item/xp/plugin/util/JarUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fun getXmlFilesInJars(config: Configuration): List<XmlFileInJar> {
val zipFile = JarFile(jarFile)

zipFile.entries().asSequence()
.filter { jarEntry -> jarEntry.name.startsWith("site") && jarEntry.name.endsWith(".xml") }
.filter { jarEntry -> !jarEntry.isDirectory && isDescriptorInJar(jarEntry.name) }
.map { XmlFileInJar(zipFile, it) }
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/no/item/xp/plugin/util/XmlFileFilters.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package no.item.xp.plugin.util

// Xml-files in an Enonic XP application that are not descriptors with forms
val IGNORED_XML_FILE_NAMES = setOf("application.xml", "styles.xml")

// Directories in an Enonic XP application that contains descriptors
val XP_DESCRIPTOR_DIRECTORIES = listOf("site", "admin", "services", "tasks", "idprovider")

/**
* Returns true if [entryName] (a path in a jar-file, using "/" as separator) is a descriptor that code should be
* generated for
*/
fun isDescriptorInJar(entryName: String): Boolean {
val fileName = entryName.substringAfterLast('/')

return entryName.endsWith(".xml") &&
fileName !in IGNORED_XML_FILE_NAMES &&
XP_DESCRIPTOR_DIRECTORIES.any { entryName.startsWith("$it/") }
}
32 changes: 32 additions & 0 deletions src/test/kotlin/no/item/xp/plugin/util/IsDescriptorInJarTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package no.item.xp.plugin.util

import org.junit.jupiter.api.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class IsDescriptorInJarTest {
@Test
fun `accept descriptors in XP directories`() {
listOf(
"site/content-types/article/article.xml",
"site/site.xml",
"admin/tools/my-tool/my-tool.xml",
"admin/widgets/my-widget/my-widget.xml",
"services/search/search.xml",
"tasks/cleanup/cleanup.xml",
"idprovider/idprovider.xml",
).forEach { assertTrue(isDescriptorInJar(it), it) }
}

@Test
fun `reject other files`() {
listOf(
"site/styles.xml",
"application.xml",
"META-INF/maven/no.item/app/pom.xml",
"lib/my-lib/config.xml",
"sites/content-types/article/article.xml",
"site/content-types/article/article.html",
).forEach { assertFalse(isDescriptorInJar(it), it) }
}
}
Loading